instance initializer

Brian Goetz brian.goetz at oracle.com
Sun Oct 6 16:21:45 UTC 2019


> In these scheme, canonical constructor also acts as instance initializer,
> since it is always called from other constructors. Classical instance
> initializer is therefore not needed any more and could be prohibited in record
> types.
>

I would agree that instance initializers in records are mostly useless, 
and keeping them around adds some complexity.  Any work that can be done 
in an II could also be done in a compact ctor with about the same number 
of keystrokes:

     { ++instanceCount; }

vs

    Foo { ++instanceCount; }

The argument for keeping them is to minimize the number of gratuitous 
differences between records and classes.  But, "it is a compile-time 
error for a record class to have an instance initializer" is a pretty 
simple spec change... and probably no one will notice.




More information about the amber-spec-experts mailing list