5 ms·
Re the first bit about 'struct' style, even better (IMO) is to use Lombok; throw an @Data annotation on your class and all you need to do is put your properties
by Cthulhu_ 11y ago
Re the first bit about 'struct' style, even better (IMO) is to use Lombok; throw an @Data annotation on your class and all you need to do is put your properties in there (private final if need be). Nobody should be writing those boilerplate constructors, getters and setters. If it's generated by your IDE, use Lombok. The best code is no code.
- chii 11y agothen you suddenly force anyone who uses your code to depend on lombok. I tried to find a compile time only mechanism for lombok - not sure i found it, but it ought to exist!
- radq 11y agoLombok does rewrite bytecode at compile time only. Your dependencies will not have to depend on Lombok.
- monksy 11y agoThats one of the things that'll happen to you if you start writting groovy code. The whole setter/getter boilerplate thing gets really annoying. Another groovy-ism.. the whole deal with having to copy properties. (In a groovy class they're threated like a map)
- vorg 11y ago> properties. (In a groovy class they're threated like a map Except in hard to remember special cases like .class which gives the class "LinkedHapMap" of the map object instead of the value at key "class". After working with Groovy for a short while you'll realize you're really working around it.
- Babylonian 11y agoLombok is a crime. Have you seen what happens when someone does a minor reformatting of your code and moves one field declaration above another? You get a nasty little surprise because the two fields of the same type have now reordered in your Lombok generated constructor. When the app runs nobody can figure out why foo is set to bar and bar is set to foo. There's also the issue of Lombok vals which don't conform to the language spec leading to other fun. And it's almost always incompatible with new jdks without code changes to the lombok libs due to the whacky way it relies on implementation specific compiler details.
- dguaraglia 11y agoWow, I didn't know this could happen. I've only recently started using Lombok for some side-project related stuff and this heads up comes at a really good time. Thanks!