4 ms·
It's good to see Java starting to waive a lot of the boilerplate. (And frustrating, when stuck on v8.)
by JulianMorrison 5y ago
It's good to see Java starting to waive a lot of the boilerplate. (And frustrating, when stuck on v8.)
- xxs 5y agoA friendly advice: dont be afraid to use public final immutable fields and omit the getters (and setters since you cant have them w/ finals).
- vips7L 5y agoProbably should just use records and get all that for free.
- xxs 5y agoJulianMorrison uses java8, no 'record' there. Not everything fits being a record, either way. The advice is sound for pretty much any class and development, use final fields in the c-tor; make them public if you have to, and dont bother w/ getters.
- JulianMorrison 5y agoI do. It bothers me this wasn't the Java Way from day one. What is with getters and setters - who subclasses and substitutes the implementation of their data carrier objects?
- deleted 5y ago[deleted]
- xxs 5y agoInitially java didn't favor getter and setters. They came with java 1.1 and the attempt bean model (and reflection) to catch visual language designers. The core java packages java.lang; java.util; java.io they dont feature getter/setters, either. If you look at the ancient AWT, there were not getter/setters - they were introduced with 1.1 and the bean stuff, most of the existing methods were deprecated. So in essence it was the original design, some book authors/design concept promoted it... Personally I have not written 'bean alike classes' for years.