java.util.LinkedHashMap无法转换为com.common.pojo.myDataDetails

时间:2018-07-09 03:50:15

标签: java

我的Java类抛出一些错误。在我的课堂上,我正在用它来获取数据。

((myDataDetails) Names.get(0)).InputParamNames().add("SomeValue");

但是它抛出错误

这是我的Pohjo班。

 package common.pojo;

import java.util.Date;
import java.util.List;

public class myDataDetails 
{
    private String myID;
    private List<String> InputParamNames;
    private List InputParamData;

    public String getmyID() {
        return this.myID;
    }

    public void setmyID(String myID) {
        this.myID = myID;
    }

    public List<String> getInputParamNames() {
        return this.InputParamNames;
    }

    public void setInputParamNames(List<String> InputParamNames) {
        this.InputParamNames = InputParamNames;
    }

    public List getInputParamData() {
        return this.InputParamData;
    }

    public void setInputParamData(List InputParamData) {
        this.InputParamData = InputParamData;
    }

}

为了避免这种异常,我需要在pojo中进行哪些更改。

1 个答案:

答案 0 :(得分:-2)

您的类“ myDataDetails”需要从LinkedHashMap扩展才能进行投射。

您现在拥有的是一个普通的POJO类,它不是LinkedHashMap的实例,所以您不能像这样强制转换它。

编辑:它应该像这样

package common.pojo;

import java.util.Date;
import java.util.List;
import java.util.LinkedHashMap;

public class myDataDetails extends LinkedHashMap<Object, Object> 
{
    private String myID;
    private List<String> InputParamNames;
    private List InputParamData;

    public String getmyID() {
        return this.myID;
    }

    public void setmyID(String myID) {
        this.myID = myID;
    }

    public List<String> getInputParamNames() {
        return this.InputParamNames;
    }

    public void setInputParamNames(List<String> InputParamNames) {
        this.InputParamNames = InputParamNames;
    }

    public List getInputParamData() {
        return this.InputParamData;
    }

    public void setInputParamData(List InputParamData) {
        this.InputParamData = InputParamData;
    }

}