Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's good to see Java starting to waive a lot of the boilerplate. (And frustrating, when stuck on v8.)


A friendly advice: dont be afraid to use public final immutable fields and omit the getters (and setters since you cant have them w/ finals).


I 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?


Initially 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.


Probably should just use records and get all that for free.


JulianMorrison 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: