-2

我是 Java 新手。我想用测试数据创建 Java 对象并从远程类访问该对象。我创建了这个对象:

public class TestAgentData
{

    public TestAgentDataObj tad;

    public class TestAgentDataObj
    {

        public int agentId = 1234;
        public String agentName = "AgentName";
        public String description = "AgentDscription";

        public TestAgentDataObj(int agentId, String agentName, String description)
        {
            this.agentId = agentId;
            this.agentName = agentName;
            this.description = description;
        }

        public int getAgentId()
        {
            return agentId;
        }

        public void setAgentId(int agentId)
        {
            this.agentId = agentId;
        }

        public String getAgentName()
        {
            return agentName;
        }

        public void setAgentName(String agentName)
        {
            this.agentName = agentName;
        }

        public String getDescription()
        {
            return description;
        }

        public void setDescription(String description)
        {
            this.description = description;
        }
    }

    public TestAgentDataObj getTad()
    {
        return tad;
    }

    public void setTad(TestAgentDataObj tad)
    {
        this.tad = tad;
    }
}

我试图从远程类访问对象:

对象 eded = new TestAgentData.getTad();

但我在 Netbeans 中遇到错误。你能说出在 Java 对象中访问数据的正确方法是什么吗?

4

1 回答 1

0

我认为您需要更好地了解java。这其中有很大的错误。您无法创建对象的方式是错误的new TestAgentData()

您不能从类型对象调用 getTad(),因为Object 类Object中没有定义方法。getTad()而是执行以下操作

TestAgentDataObj obj=new TestAgentData().new TestAgentDataObj();
TestAgentData eded = new TestAgentData();
eded.setTad(obj);
TestAgentDataObj result=eded.getTad();
于 2013-07-04T19:44:54.220 回答