Forums Register Login

Primitives class type

+Pie Number of slices to send: Send
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:

Why?
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 ?

Pho

[This message has been edited by Pho Tek (edited April 23, 2001).]
+Pie Number of slices to send: Send
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
and

failes, boolean is a primative and NOT an Object
------------------
Hope This Helps
Carl Trusiak, SCJP2
Seriously? That's what you're going with? I prefer this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 804 times.
Similar Threads
Images in a JTable
Object obj = Boolean.class
primitive types not castable as lang.Object
display a checkbox in a table
Boolean.TYPE????
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 21:18:56.