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
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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:
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?