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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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.