File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Primitives class type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Primitives class type" Watch "Primitives class type" New topic

Primitives class type

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

I have a function that expects two things:
f (Class type, Object o) { ... }
Now I can pass in a boolean wrapper class like this:

But I can't pass in a boolean primitive:

I understand that class Class is a subclass of Object right?
So I tried java.lang.Boolean.TYPE to represent the type like this:
f (java.lang.Boolean.TYPE, b); // doesn't work either
But this works:
f (java.lang.Boolean.TYPE, new Boolean(b));
why oh why ?
Is java.lang.Boolean.TYPE = boolean.class ?


[This message has been edited by Pho Tek (edited April 23, 2001).]


Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
In java primative types boolean, int, long ,float etc. are not Objects and do not subclass object.
Thats why

compiles, you pass an Object Boolean

failes, boolean is a primative and NOT an Object
Hope This Helps
Carl Trusiak, SCJP2

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
I agree. Here's the link:
subject: Primitives class type
Similar Threads
Images in a JTable
primitive types not castable as lang.Object
display a checkbox in a table
Object obj = Boolean.class