Re: Generics and Enums



Roedy Green wrote:
On Sun, 29 Jul 2007 10:55:27 -0700, "amberarrow@xxxxxxxxx"
<amberarrow@xxxxxxxxx> wrote, quoted or indirectly quoted someone who
said :

I'm trying to write a generic class that takes an Enum as generic
parameter but
I'm not able to compile it:
------------------------------------
public class Foo<T extends Enum> {

Your class is similar to an EnumSet in terms of its Generics. So I
had a peek at how EnumSet does this

public abstract class EnumSet<E extends Enum<E>> extends
AbstractSet<E>
implements Cloneable, java.io.Serializable

This would allow the OP to eliminate the illegal "T.values()" expression and just call "values()".

--
Lew
.



Relevant Pages

  • Re: Generics and Enums
    ... I'm not able to compile it: ... public class Foo<T extends Enum> { ... Your class is similar to an EnumSet in terms of its Generics. ...
    (comp.lang.java.help)
  • Re: question on multidimensional array
    ... > other compile errors in addition to that.. ... > voor het frame ... > public class Speelveld ...
    (comp.lang.java.help)
  • Re: [OT] Win32 JNI Console Class [was: Re: Clear the Screen]
    ... I know from some experience with Linux, the native code you are making into ... So when you are making your shared library you need to compile it with the ... If the library is compiled without being position independent then when you ... >> public class Console ...
    (comp.lang.java)
  • Re: Hiding base class methods
    ... "Tim Wilson" wrote: ... > compile since the method does exist. ... > public class Base: System.Object ... >> then the method of the derived class shows up. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Feature request for C# Generic inheritence
    ... I thought that for generic inheritance, the compiler will create an explicit type at compile time. ... Same way anonymous method works. ... public class GenericDecorator: T ... extender.Data (give the same ability as EventArgsbut more generic which can leverage other types that do not support generics. ...
    (microsoft.public.dotnet.languages.csharp)