Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从其名称中获取一个类,如下所示:
public void getClass(String nameOfClass){ Class<?> c = Class.forName(nameOfClass); // Doesn't work doSomethingWith(c); }
但是代码不起作用。如何根据名称获取课程?
您需要将完全限定名称传递给Class.forName(String name)方法。
Class.forName(String name)
像这样
Class.forName("some.package.SomeClass");