Another thing that I would have learnt had a read a Java Language Specification:
There are instance inistialisers in Java
Discovered May 2006
In java, a class can have an instance initialiser, which is executed before constructor is called. I knew about static initialisers that are called when the class is loaded, but never heard about instance initialisers. A colleague taught me that
class Foo { private int i; {i = 5;} //instance initialiser }
It is sometimes useful in anonymous classes as they cannot have a constructor.
Added to Things that I still discover about Java.
Свежие комментарии