#1644 readonly fields in Mixin

jessevdam Mon 12 Sep 2011

How can I make a mixin field readonly, when I try to do

mixin SVGURIReference
{
  abstract SVGAnimatedString? href {private set}
}

It says

Invalid combination of 'private' and 'virtual' modifiers

Secondly the java stub is now also automaticly creating an interface including the setter, which should also be removed when the field is readonly

dsav Tue 13 Sep 2011

You can declare a method rather than a field: abstract SVGAnimatedString? href() This makes a little difference, since you don't need () when accessing it. In implementations, you also may override this slot with const field, if you want it to be truly const.

brian Tue 13 Sep 2011

Mixins cannot allocate storage themselves, rather a field in a mixin is essentially an contract that an implementing class has a getter and setter for that slot. So if a subclass were to hide the setter, that would essentially be like trying to hide the public setter method which would break the type contract. What you can do as @dsav suggests is to just have a no-arg methods. Virtual no-arg methods can be overridden by subclasses as fields (const, private setter, etc).

Login or Signup to reply.