Wrapper classes are useful whenever it is convenient to treat a primitive data as if it were an object. because some methods take only object parameters, in those cases to pass the primitive data types, we need to convert them into wrapper classes and pass them to those methods...,
There is no need for something parallel to instanceof for primitives because the compiler can always tell from the code what the type is. Its only reference types that have to be checked at runtime. Bill
Sorry I didn�t ask what you are answering to me, the question is about the instanceof operator, not about wrapper classes, let�s try to be more clear. If a have an Integer object I can find if it is an Integer by using the instanceof operator. eg. Integer i = new Integer(1); if (i instanceof Integer) ... The question is: I can�t use the instanceof operator for primitive types but, do I have a method for knowing the exact type of a primitive? The wrapper classes have a constant var named TYPE that is of Class type (reflection). I remember I read that there was a way for checking something like this with primitives... In the Class class you have a isPrimitive() method but I want something more precise. Thanks
Joined: Jun 28, 2000
Bill: I posted the other reply without reading your answer. Thanks, you are right, but I remember I read something a long time ago about this, but don�t remember exactly what it was. It doesn�t matter, I�ll try to find it, if exists, I�ll bring back to the forum again. Thanks again.