I don't think so. A compact constructor (or require initializer, as you propose) could be not the only constructor. An instance initializer is convenient because it's added to every constructor, regardless of whether it's compact or not. So the new thing doesn't supersede the instance initializer and I see no good reason to explicitly disable it.

Vicente offered another reason why we might want to prohibit the instance initializer, if only out of expediency; it complicates the analysis of which fields are DA on all paths through the constructor (and therefore, do not need to be automatically initialized.)  If you have a record:

    record Foo(int i) {
        { this.i = 0; }
    }

then the canonical constructor has to see that `i` is always initialized by the static init, and therefore should be not initialized.  Worse, if we have:

    record Foo(int i) {
        { if (tuesday) this.i = 0; }
    }

then we have to issue a compilation error, since we have fields that are neither DA nor DU at the end of the initializer.

None of this is impossible to do, of course; it's just not clear whether it's worth it, given the limited utility of instance initializers in records (because we've already banned instance fields.)

Reply via email to