0

The existing superclass is in binary mode. Existing framework will always call superclass itself or its extension and not able to overwrite. By writing subclass extending it, I need some piece of code running before the execution of static block in its superclass.

Victor Wang
  • 41
  • 2
  • 7
  • Why not put your new code somewhere else instead (in a normal method)? – user253751 Jan 30 '15 at 00:17
  • The existing framework possess restriction that the entry point has to be an extension of existng superclass or superclass itself. – Victor Wang Jan 30 '15 at 00:19
  • Take a look at this question: http://stackoverflow.com/questions/9130461/when-is-the-static-block-of-a-class-executed – Chthonic Project Jan 30 '15 at 00:19
  • I don't have place to put Class.forName(fqn, true, classLoader) as framework itself is blackbox and will always call superclass itself or its extension, by calling its extension, static block in superclass will always be executed first. – Victor Wang Jan 30 '15 at 00:24
  • 1
    I would say you can't do it because superclasses are initialized before subclasses and therefore the static block of the parent class is always executed first. See [JLS 12.14.1 When Initialization Occurs](http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.4.1) – Tobías Jan 30 '15 at 00:26
  • I know this is tricky as when code visibility comes into play. But is there any other way I can bypass the static to exec my code somehow first? – Victor Wang Jan 30 '15 at 00:28

0 Answers0