java - Alternative styling for get and set methods -


We are all familiar with Java's "Getter and Setter" method, this is a great way to create data encapsulation; It is to ensure that any private sector outside the class code can only be accessed through these special methods. These methods may include checks, overheads, synchronization, etc.

  public class person () {the name of the private string; Private Ent Birth Year; // traditional gestetter / setter syntax public string getName () {return name; } Public int getBirthYear () {return birth year; } Public Zero Setname (string name) {this.name = name; } Public Zero Set Birth Time (Birthday Age) {this.birthYear = Birth year; } // Proposed overloading gator / setter syntax public string name () {return name; } Public birth year (year); Year back; } Public Zero Name (string name) {this.name = name; } Public zero birth year (int birth year) {this.birthYear = birth year; }}  

My question is, is there anything wrong with using the overloading method above the "proposed" syntax for gesteters / sets? I find this more readable and comfortable:

  person p = new person (); P.name ("bob"); Println (p.name ());  

I think the major disadvantage is that everyone is used to get / set syntax that will make things less readable. Anyway, this is not a big issue, I have no problem using the gates / sets, but I have thought in this alternative way that looks beautiful to me and wants to know what other people think?

Thanks

Yes though "go" and "set" are just a conference - Still, they are absolutely necessary for Java Beans to work properly with reflection.

You can read more about it or about it


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -