Dynamically loading a class in Java

后端 未结 3 2035
时光取名叫无心
时光取名叫无心 2020-12-06 04:37

I looked up the syntax and searched the api but am still confused about the process. I also searched Stackoverflow. What is the proper way to load a class and create an obj

3条回答
  •  情书的邮戳
    2020-12-06 05:19

    Assuming the class has no-arg constructor, the simplest way would be -

    Object newObject = Class.forName(strFullyQualifiedClassName).newInstance();
    

    Reference - java.lang.Class

提交回复
热议问题