I just upgraded my Dart Editor (0.5.16_r23799), and code that was bug/warning free, is not anymore.
class Fubar {
const BAR = 1000000;
Fubar(){
}
}
Lines beginning by const
have marker and this message :
Only static fields can be declared as 'const'
I read this ch02-final-const, nothing there.
This post dart-const-static-fields says that const modifier implies static
, if we can't use const
without static
, we should use final
instead ?... but what doc/post I missed ? Intend to do this :
Fubar f = new Fubar();
some = f.BAR;
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:
- No const instance fields.
- Metadata is statically scoped.
- 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With