Re:Data Classes for Java
by systoll on Thursday November 02, 2017 @05:54AM
(#15609023)
The concept of getters & setters exist in languages where it's not conventional to write them as methods named getX() or setX(y).
Writing the that example in C#, you'd likely have
public double Kelvins {get; set;};
public double Celsius {
get { ... };
set { ... };
}
and [modern] Javascript could have
let kelvins;
get celsius() { ... };
set celsius(c) { ... };
And you'd set both of them with [eg] s.celsius = 5. This is how getters/setter look when a language supports them.
Writing and using methods named 'getX' and 'setX' is conventional in Java because support for this feature doesn't exist at the language level, but is essentially implemented by the common IDEs. Probably not the ideal situation, but that's where Java is at.
Writing the that example in C#, you'd likely have
and [modern] Javascript could have And you'd set both of them with [eg] s.celsius = 5. This is how getters/setter look when a language supports them.Writing and using methods named 'getX' and 'setX' is conventional in Java because support for this feature doesn't exist at the language level, but is essentially implemented by the common IDEs. Probably not the ideal situation, but that's where Java is at.