Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 对于泛型类型错误-类不兼容_Java - Fatal编程技术网

Java 对于泛型类型错误-类不兼容

Java 对于泛型类型错误-类不兼容,java,Java,我上过这样的课 public SelectOption(SysMyAbDao dao,Class<E> entity,String idName, String labelName ){ this.dao = dao; this.entity = entity; entityAll = dao.findAll(); try{ Method idMethod = this.entity.getMethod(idName);

我上过这样的课

public SelectOption(SysMyAbDao dao,Class<E> entity,String idName, String labelName ){

    this.dao = dao;
    this.entity = entity;
    entityAll = dao.findAll();
    try{
        Method idMethod = this.entity.getMethod(idName);
        Method labelMethod = this.entity.getMethod(labelName);
        for ( E single : entityAll) {
            optionList.put((String)idMethod.invoke(single),(String)labelMethod.invoke(single));
        }
    }catch (NoSuchMethodException ex){
        ex.printStackTrace();
        logger.error(ex.getMessage());
    } catch (InvocationTargetException e) {
        logger.error(e.getMessage());
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage());
    }
}
我有个错误:

不兼容的类型。 必需:java.lang.Class 发现:E

但是如果我使用

    Class<E> single : entityAll
Class-single:entityAll
我明白了

java.lang.ClassCastException:it.survey.model.AppQuestion不能强制转换为java.lang.Class


其中it.survey.model.AppQuestion是我传递给构造函数的E类

entityAll的类型是什么?它是ArrayList
    Class<E> single : entityAll