Discerning Primitive Types

Hey everyone,

I’ve been programming in Java for a good many years now, but this sort of problem has never come up before.

You can tell what type of class a reference is by doing

if (obj instanceof java.lang.String)
System.out.println(“It’s a string!”);

But how can you discern between primitives? Is there a reserved word for it, or is there some other special trick?

Thanks!

I guess you have to use the wrapper types.
If you have a variable which you don’t now the type it is from type Object…?

Just my 2 cents…


Integer.TYPE;
Double.TYPE;
Float.TYPE;
etc...

These are the class type definitions for their coresponding primitives.