Skip to main content

Ternary that recognises polymorphism

1 reply [Last post]
Joined: 2005-02-19

My suggestion (quite simply!) is to make the following acceptable: -

boolean iNeedAVector = true;
List l = (iNeedAVector) ? new ArrayList() : new Vector();

Since the ternary always evaluates to a List, why is this not acceptable? I would suggest that the following should also work (for the same reasons): -

boolean iNeedAString = true;
Object o = (iNeedAString) ? "string" : new Integer(1);

What do you guys think?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-19

We've covered this before. It's already 'fixed' in tiger.!execute.jspa?forumID=23&forceEmptySearch=true&q=ternary&objID=f23&dateRange=all&userID=&numResults=30