javaarraylistdefault-constructorsynthetic

Preventing the creation of a synthetic constructor


While exploring the ArrayList class, I can't figure out the following part (constructor of the inner class Itr):

// prevent creating a synthetic constructor
Itr() {}

I kinda understand what the "synthetic stuff" in java is, but why do we need to prevent its creating?

Could you, please, explain some moments like is it necessary to do all the time, or there is some specific situation etc?


Solution

  • This was introduced as a fix for bug 8166840 which describes a possible performance improvement in a very specific situation.

    Note that the comments on the bug mention that this should probably removed in Java 11.


    IMHO it is nice to know that such specific optimizations are possible, but I would refrain from introducing such optimizations into my own code bases if not clearly shown by a rigid benchmark that this really, really improves the performance in my own code base.