Why only static fields can be declared as ‘const’?

This is a recent change related in the Notes From the June 4 Dart Language Design Meeting :

const instance variables

Gilad’s view is that they should work like statics except for scoping. Apparently, though, it’s complicating the VM implementation of instance metadata. Three solutions:

  1. No const instance fields.
  2. Metadata is statically scoped.
  3. Try to do it correctly.

Lars likes 1. I say 1 simplifies things for users. Right now, people get confused with static final const etc. Gilad is OK with 1.

I asked if the syntax would be “static const” or just “const”? Users get confused when having to do “static” with constants.

Lars says they are confused because they don’t understand the system. Requiring “static” will help them understand what’s going on.

Leave a Comment