22 ms·
Is that not what final does? I'd be interested in seeing C#-like getters and setters. As long as they're just getting and setting, they're implied, but if you
by mseebach 12y ago
Is that not what final does?
I'd be interested in seeing C#-like getters and setters. As long as they're just getting and setting, they're implied, but if you want to introduce a check or some other logic, you can do so without changing the signature of the class.
Groovy does some of this, but it requires you to use the name of the field - ie. person.age will check for a getAge() method first, then fall back on the "age" field. I quite like that methods have verb-names, but I don't want to verb my fields.
- exabrial 12y agoYes, sort of like final... but different. I was thinking this is more for _public_ variables... so like internally, a class could modify it's own readable fields, but code external could read only.
- breischl 12y agoI do like how C# handled this, FWIW. public int MyProperty{ get; //public private set; //private-only setter } but obviously there are a lot of ways to skin that cat.
- lmm 12y agoMethods that actually do something should be verbs, but if it's just reading a property it should look like it's just reading a property. And having all the methods on a class start with get* is a pain for autocompletion.
- mseebach 12y agoHmm. I guess you're right. I dislike Groovy in other areas so it's not a path I've gone deep down. Especially for private APIs i Java I have actually tended to default to public final members, without verbs.