Getting class by its name

后端 未结 5 1266
既然无缘
既然无缘 2020-11-28 07:58

If I have an Activity class called TestActivity in my application, is there a way to get its class by its name like in this example:

Class c = getCl         


        
5条回答
  •  自闭症患者
    2020-11-28 08:10

    The Class.forName seems to have exceptions on it. This is just to expand upon the above to address this issue.

    try { t = Class.forName("com.package.classname"); } catch (Exception ignored){}
    

提交回复
热议问题