how do I make Class.forName("Integer") returning java.lang.Integer?

S

Stefan Ram

If you want to find the class that represents
java.lang.Integer, you can do this with:
Class<Integer> integerClass=Integer.class;

The class that represents »java.lang.Integer« is
»java.lang.Integer.class«.

The class that represents »Integer« is »Integer.class«.

If both class designations refer to a class, in a specific
expression, they do not have to refer to the same class.

However, a specific import declaration, such as

import java.lang.Integer;

would make the two class designations refer to the same class.
 
R

ricky.clarkson

This forum post [1] describes how to *change* the classpath at runtime.
However, URLClassLoader also has methods [2] to get the URLs of the
classpath entries, which you can then look at using filesystem and jar
extraction methods. It isn't pretty.

I don't know of any uses for reflection that are appropriate outside
dynamically loading plugins, and even then a fully-qualified class name
is a good idea. Please explain WHY you want this, i.e., the real-world
problem you are trying to solve. There is a better way.

[1]
http://forum.java.sun.com/thread.jspa?forumID=32&messageID=1961099&threadID=300557
[2]
http://forum.java.sun.com/thread.jspa?forumID=32&messageID=1961099&threadID=300557
 
R

ricky.clarkson

Stefan,
If both class designations refer to a class, in a specific
expression, they do not have to refer to the same class.

What do you mean by class designations, and 'both' here?

I think there's some context you're keeping to yourself!

Ricky.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top