Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Type of object?

Name: Anonymous 2010-04-01 11:15

Sup /prog/riders?

I have a common problem (I guess).
I have an abstract class "X" and two classes ("A" and "B") that inherit from it. Also I really need a list that can handle both of them.

List<X> mylist;
mylist.add(A);
mylist.add(B);

Now I need to pick out all items of type A and do something with them, possibly using methods only available in class A and NOT in X or B. In ENTERPRISE JAVA there is "instanceof" but using that sounds just as hacky as saving a type in every object.


Is there a CLEAN way of determining if the object from the X-list is of type A?
Not Java-specific, rather OOP in general.

Name: Anonymous 2010-04-01 12:54

>>21
That doesn't set up a good tone for the rest of the thread, especially when you are being retarded - what defines ``clean''? Clean to look at, or generated-bytecode-type-clean?
What do you have against instanceof, especially when it's the kind of operator pertinent to your situation?
Why did you bother posting a question, only to come up with a completely unrelated answer not 38 minutes later? You couldn't have expected anyone to follow your train of thought, especially when you give them no clues as to what you do want (you only said what you don't want, and the human mind doesn't work on negatives - whatever you do, don't think of a puppy right now).

Ask a stupid question (or what effectively amounts to no question), get >>2-1000 as an answer.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List