_This issue was originally filed by domi...@google.com_
Consider a class containing (static) utility functions. Some of these functions use a static list that cannot be initialized without a constructor, but constructing an instance of this class doesn't make sense.
Having a static constructor that is called before main would be very useful. The usual issues exist here regarding order of static construction, but a simple rule would be to initialize in order of #source. Circular dependencies become an issue, of course.
Example:
class MathUtils {
static final List<double> sinLUT;
// Proposed syntax:
static () {
sinLUT = new List<double>(LUT_LENGTH);
for (int i = 0; i < LUT_LENGTH; ++i) {
sinLUT[i] = Math.sin(i * LUT_PRECISION);
}
}
}
_This comment was originally written by [email protected]_
_Removed Type-Defect label._
_Added Type-Enhancement, Area-Language, Triaged labels._
Sorry, this is where we draw the line. The whole static initialization morass a la Java is something that will not happen in Dart. Some very different solution may evolve over time.
_Set owner to @gbracha._
_Added WontFix label._
oooh noooooo
Most helpful comment
oooh noooooo