EL和协变返回类型 [英] EL and covariant return types

查看:85
本文介绍了EL和协变返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些课程

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;
    }

    ...
}

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),所以这是一个错误吗?

i can understand that covariant return type can confuse EL (2.2), so is this a bug?

我可以使用

  1. 泛型
  2. 将setType签名更改为public void setType(UnitType type)并检查其中的instanceof
  3. 更改方法名称以避免覆盖
  1. generics
  2. change setType signature to public void setType(UnitType type) and check instanceof inside
  3. change method name to avoid override

有替代解决方法的真实解决方案吗?

is there a REAL solution instead of workarounds?

推荐答案

似乎是java.beans.Introspector的原因. Java中有许多相关的错误: 7092744 6528714 6794807 6788525 .由于合成桥方法,协变量返回类型和泛型出现了问题.对于Java 7的一些更新(45、51、67、71),问题并非以正确的方式出现,而是在服务器运行了一段时间后出现的-这可能与Introspector和相关类中的软引用/弱引用缓存有关.

Seems like java.beans.Introspector is responsible. There were a lot of relevant bugs in Java: 7092744, 7122138, 6528714, 6794807, 6788525. Problems manifest with covariant return types and generics due to synthetic bridge methods. With some Java 7 updates (45, 51, 67, 71) problems manifest not right way but after running the server for some time - this is probably related to softly/weakly referenced caches in the Introspector and related classes.

所有这些问题似乎已在Java 1.7.0_80中得到修复(已在Mojarra 2.2.8和Wildfly 8.2.0.Final中进行了测试).

All these problems seem to be fixed in Java 1.7.0_80 (tested with Mojarra 2.2.8 and Wildfly 8.2.0.Final).

这篇关于EL和协变返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆