简体   繁体   English

将类型Class存储在Array或ArrayList Java中

[英]Store type Class in an Array or ArrayList java

My primary goal here is just to have an Arraylist or array that holds type Class. 我这里的主要目标只是拥有一个持有Class类的Arraylist或数组。 What would the easiest way to go about this? 最简单的方法是什么?

I don't really want to create an object to just to call getClass(). 我不是真的想创建一个对象只是为了调用getClass()。

Class[] classes = { someObject.getClass(), someObject1.getClass() };

The most ideal way to do this would be just to just call the name of the class. 最理想的方法是仅调用类的名称。 Is this possible? 这可能吗?

Class[] classes = { SomeObject, SomeObject1 };

The reason why I want to do this is because I have a static object that I hold onto and I want to see if it is an instanceOf whatever is in my array. 之所以要执行此操作,是因为我拥有一个静态对象,并且想要查看它是否是instanceOf或数组中的任何实例。

是的,有可能。

Class[] classes = { SomeObject.class, SomeObject1.class };

我不确定您要达到的目标,但这也许会有所帮助:

Class[] classes = {SomeObject.class, SomeObject1 .class };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM