They had to do this to reduce the bytecode footprint for
mobile devices (or something like that - after the third go 'round, my
eyes
glazed over and I quit trying).
Ewwww.... :)
Does "myvar = x" really indicate that you
are calling something as well as "setMyvar(x)"?
To my way of thinking (again opinion and style) getter/setter "methods"
are extremely lightweight, where method calls may not be. And why does
it matter if you're calling something or not? Seriously, with a good
optimizing language compiler (c#->IL orJava->ByteCode) and JIT compiler
(IL/ByteCode->machine code) your running code will likely not look
anything like you thought it did anyway. With the language compiler
doing code rewriting, and some inlining and the JIT doing more inlining
and throwing entire hunks of the code away if it knows it's not going to
be used in this invocation.
What I do like is that if I have to add a second parameter to the
setter, I already have the code in place and I just have to add
the variable, whereas if I have to change the
"myvar = x" syntax, it's more of a change.
OK, so actually, "setter" and "getter" are a convention thing in Java,
not a language thing? Correct? Does Java have "properties" as part of
the language spec?
In the .net mvar=x syntax there is _no way_ you could add a second parm
to a setter or getter. The getter returns a T and takes no parms and the
setter returning nothing and takes a T where T is the property type
(string, int, Object, etc.). And you don't actually ever see those parms
in the code.
String FirstName {
Get {return _firstName;}
Set {_firstName = value;}
}
Is the property FirstName in c#. The "value" in the setter is a reserved
word that stands in for the input parm to the setter. And you could, of
course, leave out the get or set line to have a write-only or read-only
property.
If you wanted to add a "second" parm to your you're create a method that
did what you wanted.
-Walden
As an Amazon Associate we earn from qualifying purchases.