1

I've been coding Java almost since it started, and yet I learned today that there exist instance initialization blocks (see: What is an initialization block?). I was sure that static initialization blocks were the only option.

Since when have the instance initialization blocks been part of the language? I'd appreciate if the answer is backed up by documentation.

MaDa
  • 10,511
  • 9
  • 46
  • 84
  • [Java Language Specification version 2](http://www1.cs.columbia.edu/~sedwards/papers/gosling2000java.pdf#page=214) mentions them, so they've been around for a while. – Andy Turner Sep 08 '17 at 10:10
  • 1
    @a_horse_with_no_name: No, it was *much* earlier than Java 6. – Jon Skeet Sep 08 '17 at 10:14

1 Answers1

2

Instance initializers were added in Java 1.1.

Old versions of language documentation are somewhat spread around the web (Oracle hasn't kept a lot of them) but this document appears to be a copy of original tutorial docs, and shows the language changes for 1.1:

  • Inner classes
  • Anonymous classes
  • Instance initializers
  • Array initialization
  • Class literals
  • More places where final can be used
  • transient having a defined meaning
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thank you. So, it appears that they've been around almost since the beginning. They're not widely advertised, though. – MaDa Sep 08 '17 at 13:28