Situation
A directory full of '.class' files, in appropriate subdirectories according to their class path.
Desire
Get a Class instance for each of those '.class' files, without resorting to string manipulation to get 'fully qualified class names' for each of the files.
Research
I've seen plenty of ways to get a Class instance from a string.
What I'd like to do is avoid strings altogether, and just do something like this:
/**
* Foo Description Here
*
* @parameter file A File instance referring to a '.class' file.
*/
public Class<?> Foo(File file) {
...
return someClassLoader.loadClass(file);
}
The "file" argument already refers to a '.class' file. I already know that I could massage the path from the 'file' argument, and get to something that is recognizably a fully qualified class name. I want to avoid all that messing about with strings if I can.
I've already seen the following:
That's exactly what I don't want to do. And I've seen:
Where the second answer comes close, but leaves open the question of how you get the fully qualified name of the class for the last step. You still have to either mess around with strings, or just arbitrarily name them as you define them.
After munching around in the JavaDocs, StackOverflow, et.al., I am beginning to wonder if there's any way to do this.