Can I Instantiate a class using the class object? What about Constructors?

后端 未结 6 754
时光说笑
时光说笑 2020-12-09 18:15

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

newInstance seems to the met

6条回答
  •  失恋的感觉
    2020-12-09 18:46

    Just to add one point I see missing:

    You can invoke newInstance directly on the Class object if it has a public null constructor. (Null constructor is the constructor with no arguments.)

    Otherwise, you can find constructors via Class.getConstructors() as others have said.

提交回复
热议问题