Forums Register Login

using `instanceof`with an "object" parameter

+Pie Number of slices to send: Send

For the below code, I get the following errors:


inconvertible types
found: Object
required: Fruit
if (o instanceof Fruit)
Fruit a (Fruit) a


I am using a java/javac version 1.6. Any idea why this is not working for my compiler ? I assume it should work because all classes inherit from Object. I thought it was referring to the wrong Object class, so I changed the method to public boolean add(java.lang.Object o), which seems to work.



+Pie Number of slices to send: Send
 

I thought it was referring to the wrong Object class, so I changed the method to public boolean add(java.lang.Object o), which seems to work.



Well, do you happen to have you own Object class, that is in the same package?

Henry
+Pie Number of slices to send: Send
Definitely do not.
Did not make one and

Made sure there are none in the directory and program is not linked to any package.

From the java API i see there's another Object interface, org.omg.CORBA
Interface Object.

+Pie Number of slices to send: Send
 

From the java API i see there's another Object interface, org.omg.CORBA Interface Object.



But unless you "import" that Object, it wouldn't be an issue. This is why I asked if you had an Object in your package, because the current package (just like java.lang) does not need to be imported.

Henry
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2148 times.
Similar Threads
Another Generics question
A Generics and Collections Problem
Question on HashSet
what is the correct answer?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:17:51.