Sdk: Feature request: Static constructor

Created on 21 Dec 2011  路  3Comments  路  Source: dart-lang/sdk

_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);
    }
  }
}

area-language closed-not-planned type-enhancement

Most helpful comment

oooh noooooo

All 3 comments

_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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmesserly picture jmesserly  路  3Comments

ranquild picture ranquild  路  3Comments

DartBot picture DartBot  路  3Comments

rinick picture rinick  路  3Comments

DartBot picture DartBot  路  3Comments