Hacker News new | ask | show | jobs
by usrusr 796 days 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.
1 comments

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

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