Skip to content

Instantly share code, notes, and snippets.

@kasramp
Created August 4, 2020 22:30
Show Gist options
  • Save kasramp/8f911329bf50db9b6547c5a7ba379ed1 to your computer and use it in GitHub Desktop.
Save kasramp/8f911329bf50db9b6547c5a7ba379ed1 to your computer and use it in GitHub Desktop.
public class Test {
public void main(String[] args) {
String className = "A";
Class myClass = Class.forName(className);
//Now need to make an object
// This is a general Object type, must convert to call method.
Object obj = myClass.newInstance();
A aClass = (A) obj;
//Shorter way
A aClass = (A) Class.forName(className).newInstance();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment