I'm trying to take an animal element of an array for filtering but I'm having some problems. I need to take the element i need out of the array. Then I need to find out whether the animal is the type I need. Finally I need to add the animal object to the array. I have to seperate arrays of displayed animals and all the animals but I'm just having trouble figuring out how to do the above. Any advice is greatly appreciated. Here's what I have so far:
You could even pass the class type into a function and reduce the duplication in the code.
I have come up against this sort of issue before and never really had the time to try to figure out why this is happening. I have always just gone with the isInstance() function instead. If somebody can explain it I would be grateful.
5 years on and still a Greenhorn, what to do, what to do?
@Allain: you're saying instanceOf doesn't work for you?
@Ron: The fragment, and that fragment embedded in the entire code, are not the same. What *is* happening, and what do you *expect* to happen?
Allain Walker
Greenhorn
Joined: May 24, 2005
Posts: 14
posted
0
Hi David,
What I am saying is that I have tried to use the instanceof before and I must have made a mistake with it, or not understood how it works. At the time instead of using instanceof I used class.isInstance(o) and achieved the outcome I was looking for.
I didn't have time to examine what I was doing wrong, and it fell of the radar. I now have the time to do that now and will try again.
Thanks
Allain