Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how do I make Class.forName("Integer") returning java.lang.Integer?

Reply
Thread Tools

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

 
 
Johannes Zellner
Guest
Posts: n/a
 
      12-18-2005
Hello,

How do I make Class.forName("Integer") returning java.lang.Integer?
To be more general:

1. How do I make Class.forName searching in some packages?


2. Can I make Class.forName respecting the import statements of the
calling class? -- e.g. in

import java.lang.Integer;
class Fred() {
Fred() {
Class.forName("Integer");
}
}

I'd like Class.forName() returning java.lang.Integer, because it
was imported earlier.

Any help much appreciated!

--
Johannes
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      12-18-2005
On Sun, 18 Dec 2005 16:59:19 +0100, Johannes Zellner
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
said :

>How do I make Class.forName("Integer") returning java.lang.Integer?
>To be more general:


see http://mindprod.com/jgloss/classforname.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      12-18-2005
On Sun, 18 Dec 2005 16:59:19 +0100, Johannes Zellner
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
said :

>2. Can I make Class.forName respecting the import statements of the
> calling class? -- e.g. in


classForName can't see the imports.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      12-18-2005
Johannes Zellner <(E-Mail Removed)> writes:
>How do I make Class.forName("Integer") returning java.lang.Integer?


"java.lang.Integer" is a Class.
A class is not a value, so it can not be returned.

To make "Class.forName" return the string
»"java.lang.Integer"«:

public class Class
{ public static java.lang.String forName
( final java.lang.Object dummy )
{ return "java.lang.Integer"; }}

(Sorry!)

 
Reply With Quote
 
J. Verdrengh
Guest
Posts: n/a
 
      12-18-2005
> "java.lang.Integer" is a Class.
> A class is not a value, so it can not be returned.


Afaik each class in Java is represented by an instance of type Class, so a
class (==instance of Class) can be returned..


 
Reply With Quote
 
J. Verdrengh
Guest
Posts: n/a
 
      12-18-2005
> "java.lang.Integer" is a Class.
> A class is not a value, so it can not be returned.


Afaik each class in Java is represented by an instance of type Class, so a
class (==instance of Class) can be returned..


 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      12-18-2005
"J. Verdrengh" <(E-Mail Removed)> writes:
>>"java.lang.Integer" is a Class.
>>A class is not a value, so it can not be returned.

>Afaik each class in Java is represented by an instance of type Class,
>so a class (==instance of Class) can be returned..


This, I would have written as »java.lang.Integer.class«.

 
Reply With Quote
 
Alan Krueger
Guest
Posts: n/a
 
      12-18-2005
Stefan Ram wrote:
> "J. Verdrengh" <(E-Mail Removed)> writes:
>
>>>"java.lang.Integer" is a Class.
>>>A class is not a value, so it can not be returned.

>>
>>Afaik each class in Java is represented by an instance of type Class,
>>so a class (==instance of Class) can be returned..

>
>
> This, I would have written as »java.lang.Integer.class«.


Not if you were calling Class.forName.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      12-18-2005
Alan Krueger <(E-Mail Removed)> writes:
>>This, I would have written as »java.lang.Integer.class«.

>Not if you were calling Class.forName.


The OP wrote:

How do I make Class.forName("Integer") returning
java.lang.Integer?
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
So "java.lang.Integer" was intended to be the value
of this expression, not the argument.

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-19-2005
On 18 Dec 2005 16:35:28 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram)
wrote, quoted or indirectly quoted someone who said :

> "java.lang.Integer" is a Class.
> A class is not a value, so it can not be returned.


java.lang.Integer is the name of a class

"java.lang.Integer" is a String, and hence an object.

java.lang.Integer.class is the Class object for Integer.

Strings and Class objects can be returned from methods.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to test python extension modules during 'make check' / 'make distcheck'? Mark Asbach Python 1 11-03-2006 02:29 AM
How does one make use of sub files to make DVD? Bun Mui DVD Video 0 05-21-2006 03:24 PM
How does one make use of sub files to make DVD? Bun Mui Computer Support 0 05-21-2006 03:09 PM
returning none when it should be returning a list? randomtalk@gmail.com Python 11 05-02-2006 10:26 AM
Anyone know how to make XP make a sound when typing? Like old dumb terminals? Fire Computer Support 6 02-17-2004 12:56 AM



Advertisments