4 ms·
The intention for "nothing before super" is clear, but that rule never delivered on its promises. Because all those footguns are still in place, in field initia
by usrusr 2y ago
The intention for "nothing before super" is clear, but that rule never delivered on its promises. Because all those footguns are still in place, in field initializers as well as in function calls inside the super() argument list:
class Sub extends Super {
int field = footgunA();
Sub() {
super(footgunB());
}
}
It's a zero merit headache factory and good intentions alone cannot change that.
- DarkNova6 2y agoAs far as I know `footGunA` can only be a static method and cannot leak `this`. This is perfectly fine as far as I'm concerned.
- usrusr 2y agoI should have checked instead of replying from memory: It's actually footgunB that is refused by the compiler. footgunA is accepted and will even call happily into an overridden implementation from a field initializer in the superclass. That way you can get a method to see a final field null on one call and non-null on the next.