我喜欢在那里这个类中认为,目前2个不同的类别中可以通过对象的列表下面的方法。的Java get方法
public class DataTableEntity {
List<Objects> objectContainer;
public void setLinks(Class cls){
for(Object obj : objectContainer){
//the cls variable will hold what type of object it is
//so I need to somehow say if its a 'dog' then the obj I am going through is a dog
// and the method is dog.getName else it might be cat and cat.getCatName etc.
}
}
此功能被告知什么列表具体是,然后应正确格式化该列表中的对象的属性,然后才发送到客户端。不同的对象对这些属性具有不同的setter和getter名称。所以我需要以某种方式采用通用的Class对象,看看它的实际类型是什么类型,以便我知道使用“.getAbc/.setAbc”或“.getXyz/.setXyz”的方法。
这可能吗?
你可能会展示更多的代码,因为从你的问题我不能真正理解你想要做什么。但其可能的和简单的 – x4rf41
基本上我只是在一个类中具有上述功能,该类具有List的属性,我们使用它作为容器通过JSON发送到此容器使用的Web客户端只是对象作为一类Dog或Cat可以放在列表中以便通过JSON传递。然而,其中一个属性需要改变,比如Dog.name,从“Fido”到“ Fido”,并且对于cat来说也是一样,但是它的名字叫Cat.catName而不是Cat.Name。所以我需要以某种方式能够通过容器列表,并确定它们是什么,所以我知道哪些属性进行格式化,然后 –
将其从通用