Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26226
| From | Lew <lew@lewscanon.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: limitations on using enum as generic parameter |
| Date | 2011-02-08 10:38 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <c93f15ae-9766-42f3-9bb0-18cea537e111@u14g2000vbg.googlegroups.com> (permalink) |
| References | <76e9be77-f846-4559-82ec-1d774a8a6a0b@q36g2000yqn.googlegroups.com> <iis2c4$egq$1@news.eternal-september.org> |
On Feb 8, 1:34 pm, markspace <nos...@nowhere.com> wrote:
> On 2/8/2011 9:50 AM, dal...@cs.queensu.ca wrote:
>
> > situations, I tried writing a generic class that takes an enum as a
> > type parameter. Unfortunately I don't seem to be able to invoke the
> > enum's values() method -- javac says "Cannot find symbol: method
>
> Yes, values() and valueOf(String) are /static/ methods. They don't
> appear on the Enum interface so the compiler doesn't know about them.
>
> You can try object.getClass().getEnumConstants() to get the constants
> themselves in order.
>
> Also you should probably be declaring you enum as <E extends Enum<E> & ...>.
>
> Untested:
>
> public class EnumCodeSet<E extends Enum<E> & MessageCode>
> {
> private final E[] enums;
>
> public EnumCodeSet( E anEnum ) {
> enums = anEnum.getClass().getEnumConstants);
> }
>
> public MessageCode index( int i ) {
> return enums[i];
> }
>
> //... etc.
>
>
>
>
Also, generics and arrays don't mix. So don't mix them.
--
Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
limitations on using enum as generic parameter "dalamb@cs.queensu.ca" <david.alex.lamb@gmail.com> - 2011-02-08 09:50 -0800
Re: limitations on using enum as generic parameter Lew <noone@lewscanon.com> - 2011-02-11 07:36 -0500
Re: limitations on using enum as generic parameter Daniele Futtorovic <da.futt.news@laposte.net.invalid> - 2011-02-08 20:36 +0100
Re: limitations on using enum as generic parameter Ken Wesson <kwesson@gmail.com> - 2011-02-08 19:46 +0100
Re: limitations on using enum as generic parameter Roedy Green <see_website@mindprod.com.invalid> - 2011-02-10 22:50 -0800
Re: limitations on using enum as generic parameter Roedy Green <see_website@mindprod.com.invalid> - 2011-02-10 22:47 -0800
Re: limitations on using enum as generic parameter markspace <nospam@nowhere.com> - 2011-02-08 10:34 -0800
Re: limitations on using enum as generic parameter Lew <lew@lewscanon.com> - 2011-02-08 10:38 -0800
csiph-web