Re: Advanced Java Generics syntax question

"Gregory A. Swarthout" <[email protected]> Fri, 15 Feb 2008 14:08:00 -0700
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
Brian Maso wrote:
> I want to define an anonymous subclass of a generic class -- how do I
> set the parameter type?
>
> Here's a non-anonymous example of a subclass binding the superclass
> type variable:
>
> public LinkedListOfStrings extends LinkedList<String> {
>   ...
> }
>
> That's no problem. Now let's say I want to do the same thing but with
> an anonymous inner class:
>
> class Outer {
>
>   public void someMethod() {
>
>     LinkedList<String> lls = new LinkedList() {  <-- how do I
> indicate the superclass is LinkedList<String>?
>       public void add( String s ) { ... }
>       ...
>     }
>
>   }
>
> }
>

Sorry, previous post had following line transposed.

LinkedList<String> lls = new LinkedList<String>() {
       public void add( String s ) { ... }
};

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com