aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Determine type of a primitive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Determine type of a primitive" Watch "Determine type of a primitive" New topic
Author

Determine type of a primitive

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Is there any way to determine the type of a primitive?
Vishy Karl
Ranch Hand

Joined: Sep 08, 2003
Posts: 116
I think No there is method for objects but I don't think there is for primitive.
Others do correct if you feel I am wrong,
Bye
Vishal.


"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister
Ed Tse
Ranch Hand

Joined: Sep 18, 2003
Posts: 183
can you post the scenario? when do u need that?


SCJP, Pre-SCJD (URLyBird 1.3.1), Teradata Cert'd Prof
Danijel Kucak
Greenhorn

Joined: Sep 17, 2003
Posts: 2
Originally posted by Vishal Kalra:
I think No there is method for objects but I don't think there is for primitive.
Others do correct if you feel I am wrong,
Bye
Vishal.

i think there is no method for objects, it's operator instanceof
Bye,
Danijel
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
class Test {
public static void main(String[] args) {
int i = 0 ;
System.out.println(/** print type of i **/)
}
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
How's this?
[ September 19, 2003: Message edited by: Steve Lovelace ]

The Inner that is named is not the true Inner.
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Thanks Steve. That is great. But I was expecting some like this in API. By the way what is by byte.class. Never seen that before.
Thanks
Barkat
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
I doubt very much there is one.
Primitive types are not objects. You cannot do introspection on them.
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
What about if Steve's code is part of AP1 so that every client does not have write it?
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
Appears the VM builds for itself a Class object for each of the primitive types. The syntax for accessing these is <type>.class, so, byte.class, int.class, etc. Alton's right that introspection (reflection?) won't get you anywhere: Somebody know offhand what introspection is, is it different from reflection?
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Reflection is the ability of a program to use an object whose class file was not present at the time of its compilation. The program cannot name the real type of such object, it cannot name its methods or fields because the compiler would complain. Instead the program uses java.lang.reflect
I think introspection is either a synonym, or a process that uses reflection discovering JavaBeans members for a Gui Builder.
JavaBean specification
[ September 21, 2003: Message edited by: Jose Botella ]

SCJP2. Please Indent your code using UBB Code
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
Objects that are introspective(or reflective) has the ability to describe itself. Programming languages that support introspection allows objects to be examined, like, what class it came from, what are its fields and methods, etc.
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
Just a note about Typist. It really isn't anything more than a kinda cute demo of overloading and the existence of Class objects for primitives. Fact is, you can always see the declaration of a primitive variable - it's somewhere in your code, and whatever its declared to be, that's what it is. So Typist has no real purpose in life.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Determine type of a primitive