If you know the full name of the class, you can load it using the usual Java reflection methods in java.lang.Class, namely Class.forName(String fqClassName). Given the resulting instance Class, instantiating is easy only with a constructor with a null argument, otherwise you will get confused in the messy world of all Java reflection types.
If you need some kind of “discovery”, where unknown classes are at compile time and whose names are not presented as input or program parameters in some way, the approach to loading classes is probably the only answer.
source
share