|
|
|
|
|
by cvoss
717 days ago
|
|
> bazillion ordering rules There are 3 which pertain to object initialization in Java. 1. super is initialized in it's entirety by an implicit or explicit call to `super()` 2. All instance initializers of the present class are invoked in textual order. 3. Constructor code following the `super()` call is executed. The only awkward thing here is the position of #2 in between #1 and #3, whereas the text of a constructor body suggests that #1 and #3 are consecutive. It gets easier to remember when you recognize that, actually, there's a defect in the design of the Java syntax here. A constructor looks like a normal function whose first action must be a `super()` call. It's not. The `super()` call is it's own thing and shouldn't rightly live in the body of the constructor at all. Edit: Tweaks for clarity. |
|