Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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_List_Exception_Classcastexception - Fatal编程技术网

类强制转换异常Java列表到对象

类强制转换异常Java列表到对象,java,list,exception,classcastexception,Java,List,Exception,Classcastexception,在尝试将列表中的对象强制转换为我的对象时,我得到了一个ClassCastException。 我的对象如下所示: public class TestObject extends MyDataObject implements Serializable { public TestObject(String info, String text) { this.setInfo(info); this.setTeyt(text); } public String getInfo(

在尝试将列表中的对象强制转换为我的对象时,我得到了一个
ClassCastException
。 我的对象如下所示:

public class TestObject extends MyDataObject implements Serializable {


public TestObject(String info, String text) {

    this.setInfo(info);
    this.setTeyt(text);
}

public String getInfo() {

    return this.<String> get(MyDataEnum.INFO);
}

public void setInfo(String info) {

    this.set(MyDataEnum.INFO, info);
}

public String getText() {

    return this.<String> get(MyDataEnum.TEXT);
}

public void setText(String text) {

    this.set(MyDataEnum.TEXT, text);
}
}
我通过以下方式获得列表:

List<TestObject> testObject = myDataObject.<List<TestObject>>
             get("object.otherKey");

And Enum.INFO("info),
and ENUM.TEXT("text")
classcastexception在这一行抛出:

    if(testObject.get(0).getText() != null) {

请问myDataObject的作用是什么。获取(“object.otherKey”)的意思是?。那么您从哪里得到
ClassCastException
?@sᴜʀᴇsʜᴀᴛᴛᴀ 这就是当您想要显式地为采用泛型类型参数的方法指定类型时所使用的语法。请看我更新了我的原始帖子来回答您的问题。您至少需要发布stacktrace,并展示“MyDataObject”的实现。
public <T> T get(MyDataEnum key)
{
    return this.<T>get(key.getName());
}
    if(testObject.get(0).getText() != null) {