Re: Multiple bounds in a generic declaration



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".


.



Relevant Pages

  • Re: onmouseleave event in IE
    ... There is nothing harmful about using var with an already declared ... function bar(){... ... bar has access to all the variables of foo, but foo has no access to ... Some like to declare them all at the start of the ...
    (comp.lang.javascript)
  • Re: Flamebait if I ever saw it
    ... (defmethod zap ((x foo)) ... (defmethod zap ((x bar)) ... (defun checker (myfoo mybar myfoo2) ... (declare (type foo myfoo myfoo2)) ...
    (comp.lang.lisp)
  • Class data being zapped by method
    ... I'll cut to the chase. ... bar, and I set bar.data to a large list of tuples. ... Within Foo() there is a method which operates on self.data. ... constructor I do declare self.data to be an empty list, ...
    (comp.lang.python)
  • Multiple bounds in a generic declaration
    ... Both Foo is an abstract class and Bar is in this case a listener ... How can I declare this ArrayList? ...
    (comp.lang.java.help)
  • Re: Selecting class at runtime
    ... hence, whatever methods that may be used in future, through inheritance, ... should be declared as prototypes in the abstract class. ... Declare your DoStuff method as virtual so that they could be overridden ...
    (microsoft.public.dotnet.languages.csharp)