I hope this is the right section. I just have a short (hopefully simple) question: How can you convert a File object (which is a .class file) to a class<?> object?
Thanks for any help :)
Printable View
I hope this is the right section. I just have a short (hopefully simple) question: How can you convert a File object (which is a .class file) to a class<?> object?
Thanks for any help :)
Every Object in java has a getClass() method that returns the Class instance of the class. You could also use the class keyword (eg File.class )
Does that mean I could do something like:
Code :File myFile = new File(path); Class<?> myCls = myFile.getClass();
I didn't think this would work as .getClass() would return the File class and not the actual .class file. Maybe I misunderstood what you said or am mistaken in my logic.
The code you posted does exactly what your original question asked - gets the Class object from a File object. Perhaps I am misunderstanding - what you actually trying to do?