KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is there a standard acceptable convention for parameters in Java to straightforward constructors and setters? ( I've seen the answer for C++ , but practices are often different between the two communities) Suppose that I have a class C with a foo field. I have commonly seen the following three options: 1) Use the actual field name with an underscore: public C(Type foo_) { foo = foo_; } public void setFoo(Type foo_) { foo = foo_; } 2) Use the actual field name, just use "this" in setting: public C(Type foo) { this.foo = foo; } public void setFoo(Type foo) { this.foo = foo; } 3) Completely inconsistent things like: public C(Type bar) { this.foo = bar; } public void setFoo(Type bar) { this.foo = bar; } I tend to use 2, but I'm wondering what's correct practice.
Tags (comma-separated)
Save Edits
Cancel