我可以使用类对象实例化一个类吗?那些构造函数呢?

我可以使用类对象实例化一个类吗?那些构造函数呢?

问题描述:

我通过( Classname.class )存储类的列表,并希望实例化一个类?这可能吗?

I am storing a list of classes through (Classname.class) and would like to instantiate one? Is this possible?

newInstance 似乎是我所使用的方法,但它不支持构造函数?

newInstance seems to the method I am after but it doesn't support a constructor?

你不能用这种方式构建新类。

You cannot construct new classes this way.

如果你有您可以使用Class.forName(className)来加载/引用类的类的名称。

If you have the name of a class you can use Class.forName(className) to load/reference a class.

如果您有要创建的类的字节代码可以让类加载器加载字节代码并为您提供类。这可能比你想象的更先进。

If you have the byte code for a class you want to create you can have a class loader load the byte code and give you the class. This is likely to be more advanced than you intended.