是否有可能变换子类中字段的最终修饰符

时间:2016-07-04 20:26:16

标签: java inheritance immutability

情况就是这个

class Immutable
{
    public final int myField;

    public Immutable(int value)
    {
        myField = value;
    }

    //methods that treat the object as immutable
}

class Mutable extends Immutable
{
    //no longer final. The same field. Not subclass hiding superclass field.
    public int myField;

    //more methods, these mutate the state of the object
}

这可以用Java完成吗?甚至语言扩展?随着演员和所有。

0 个答案:

没有答案