Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

what is isPrimitive?

  Asked By: Anpu    Date: Oct 15    Category: Java    Views: 1180

By the explanation of isPrimitive in javadocs the following two lines of
code should print out true. What am I missing here?


Object bool = new Boolean("true");




2 Answers Found

Answer #1    Answered By: Barak Levi     Answered On: Oct 15

From the javadocs:

"There are nine predefined |Class| objects to represent the eight
primitive types and void. These are created by the Java Virtual Machine,
and have the same names as the primitive types that they represent,
namely |boolean|, |byte|, |char|, |short|, |int|, |long|, |float|, and

These objects may only be accessed via the following public static final
variables, and are the only |Class| objects for which this method
returns |true|."



should return true.

All in all it seems rather useless to me.

Answer #2    Answered By: Rosalie Holmes     Answered On: Oct 15

I agree with your assessment. I need to know if the returned value from a
method can be represented by a primitive type. I guess I will have to write
my own isPrimitive method using those types mentioned in the docs. Thanks
for the heads up.

Didn't find what you were looking for? Find more on what is isPrimitive? Or get search suggestion and latest updates.