vendredi 10 juillet 2015

Get the full path of class in Java

I have a String variable that keeps a name of Java Class (let's call it Dog) and I use this string like this:

String myString = className; Class<?> klass = Class.forName(myString);

However, this throws a ClassNotFoundException because my Dog is in a package, and I suppose Class.forName wants the full name (my.project.the.package.path.Dog). Is there a way to get the full package name so I can pass it to Class.forName()?

Thanks!





Aucun commentaire:

Enregistrer un commentaire