So, suppose I have a string str = "MyClass", now I want to use this string to find MyClass so that I can create and use it.
A simple example:
MyClass obj = Class.forName("com.xyz.MyClass").newInstance();
This assumes the existence of a default constructor and will throw various exceptions if the class cannot be found or cannot be created.
Class.forName can do what you want, but you also need the full package path.
myclass= Class.forName ( "package.MyClass" );
instance = myClass . newInstance();
package - , MyClass
Source: https://habr.com/ru/post/1777525/More articles:Grammatical question, problem with FIRST - grammarVisual Studio: how to specify different runtime libraries for the linker? (/ MTd, MDd, etc.) - c ++jquery фильтрует определенный элемент - javascriptStrange ADODB behavior - sqlIs conditional expression inside Convert.ToString () incorrect? - c #When to close a result set (ODBC core question) - sqlShould I catch all my exceptions in global.asax? - loggingAny good way to run 2 exes from VS 2008 IDE for debugging? - visual-studioR class was deleted by Eclipse after Clean Project - androidMVC project complains that it cannot find Nhibernate.dll version 2.1.0.4000 - nhibernateAll Articles