Re: Multiple bounds in a generic declaration
- From: Mark Space <markspace@xxxxxxxxxxxxxx>
- Date: Fri, 20 Feb 2009 15:22:45 -0800
Gibbering wrote:
If I need an arraylist of objects who extend something and implement
something else, how can I declare it?
ArrayList<? extends Foo & Bar> funky = new ... // Invalid
ArrayList<? extends Foo, Bar> funky = new .... // Invalid
Both Foo is an abstract class and Bar is in this case a listener
interface. How can I declare this ArrayList?
More confusion over type bounds. This kind of bound is only used for generic methods, parameters and class definitions, not actually declaring a variable or object. (I think I've used "define" and "declare" correctly there.)
abstract class Foo implements Bar, ActionListener {}
ArrayList<Foo> funky;
is probably what you want. Don't use a bound or wildcard when declaring a variable like "funky".
.
- Follow-Ups:
- Re: Multiple bounds in a generic declaration
- From: Gibbering
- Re: Multiple bounds in a generic declaration
- References:
- Multiple bounds in a generic declaration
- From: Gibbering
- Multiple bounds in a generic declaration
- Prev by Date: Multiple bounds in a generic declaration
- Next by Date: Re: Multiple bounds in a generic declaration
- Previous by thread: Multiple bounds in a generic declaration
- Next by thread: Re: Multiple bounds in a generic declaration
- Index(es):
Relevant Pages
|