Java: Create a class with a given name

Create a class with a given class name:

String className = "com.company.full.qualified.MyClass");

@SuppressWarnings("rawtypes")    
Class c = Class.forName(className);
MyClass = (MyClass)c.newInstance();   

The class name should be provided with its complete package name.

Werbung



comments powered by Disqus

Copyright Dunkel & Iwer GbR | Datenschutzerklärung | Impressum