EL和协变返回类型

时间:2013-04-16 14:11:19

标签: jsf-2 el covariance

我有这些课程

public abstract class Unit
{
    public abstract UnitType getType();

    ...
}

public class Item extends Unit
{
    protected ItemType type;

    @Override
    public ItemType getType()
    {
        return type;
    }

    public void setType(ItemType type)
    {
        this.type = type;
    }

    ...
}

且obvoiusly ItemType扩展UnitType

我得到:

javax.el.PropertyNotWritableException: /WEB-INF/facelets/general.xhtml @23,165 value="#{bean.item.type}": The class 'com.example.Item' does not have a writable property 'type'.

我能理解协变返回类型会混淆EL(2.2),所以这是一个错误吗?

我可以使用

解决此问题
  1. 泛型
  2. 将setType签名更改为public void setType(UnitType type)并检查
  3. 中的instanceof
  4. 更改方法名称以避免覆盖
  5. 是否有真正的解决方案而非解决方法?

1 个答案:

答案 0 :(得分:1)

似乎java.beans.Introspector负责。 Java中有很多相关的错误: 70927447122138652871467948076788525。由于合成桥接方法,问题表现为协变返回类型和泛型。对于一些Java 7更新(45,51,67,71),问题表现不正确但在运行服务器一段时间之后 - 这可能与Introspector和相关类中的软/弱引用缓存有关。

所有这些问题似乎都在Java 1.7.0_80中修复(使用Mojarra 2.2.8和Wildfly 8.2.0.Final进行测试)。

相关问题