aspose file tools*
The moose likes Java in General and the fly likes Quick ArrayList Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Quick ArrayList Question" Watch "Quick ArrayList Question" New topic
Author

Quick ArrayList Question

Ben Jass
Ranch Hand

Joined: Sep 25, 2010
Posts: 76
Hey guys, Let's say I have three classes: Polygon, Rectangle, and Oval. Both Oval and Rectangle extend Polygon. So now I'm creating a new ArrayList that I want to hold Polygons and anything that is-a polygon (Rectangle, Oval, etc.).

How can I make an ArrayList take Polygon objects, and any object that is a subclass of Polygon?

Just simply doing this:



Does not work.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30753
    
156

What error do you get? The following compiles and runs.



[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ben Jass
Ranch Hand

Joined: Sep 25, 2010
Posts: 76
Pointless thread, I guess it works now heh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Quick ArrayList Question