-
-
Save kasramp/8f911329bf50db9b6547c5a7ba379ed1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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