Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #25978

Re: limitations on using enum as generic parameter

From Daniele Futtorovic <da.futt.news@laposte.net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: limitations on using enum as generic parameter
Date 2011-02-08 20:47 +0100
Organization A noiseless patient Spider
Message-ID <iis6ki$ad9$1@news.eternal-september.org> (permalink)
References <76e9be77-f846-4559-82ec-1d774a8a6a0b@q36g2000yqn.googlegroups.com> <4d518f96$1@news.x-privat.org> <iis5qe$6o3$1@news.eternal-september.org> <4d519c14$1@news.x-privat.org>

Show all headers | View raw


On 08/02/2011 20:40, Ken Wesson allegedly wrote:
> On Tue, 08 Feb 2011 20:33:37 +0100, Daniele Futtorovic wrote:
>
>> On 08/02/2011 19:46, Ken Wesson allegedly wrote:
>>> That's not going to work. It's a static method of a class that isn't
>>> determined at this point in the code, so the compiler simply has no
>>> clue what to call. Hence the error message.
>>>
>>> If you really need to do something like this, you'll need to use
>>> reflection on a class object.
>>
>> For the record: no. See my and ninja markspace's replies.
>
> I meant the general case of wanting to invoke a static method on a type
> parameter, where the method depends on the run-time type (so, it's not a
> method of X where you have<E extends X>, but a method implemented
> differently for each choice of E).

I would argue that this would be bad design. Aside from cases where 
reflection is part of the contract (Spring, for instance), it should 
only be used exceptionally, if at all.

> In the special case of an enum there's getEnumConstants.

Which doesn't work via reflection, FWIW.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: limitations on using enum as generic parameter Daniele Futtorovic <da.futt.news@laposte.net.invalid> - 2011-02-08 20:33 +0100
  Re: limitations on using enum as generic parameter Lew <lew@lewscanon.com> - 2011-02-09 10:07 -0800
  Re: limitations on using enum as generic parameter Daniele Futtorovic <da.futt.news@laposte.net.invalid> - 2011-02-08 23:44 +0100
  Re: limitations on using enum as generic parameter Daniele Futtorovic <da.futt.news@laposte.net.invalid> - 2011-02-08 20:47 +0100
    Re: limitations on using enum as generic parameter Lew <lew@lewscanon.com> - 2011-02-08 12:31 -0800
  Re: limitations on using enum as generic parameter Ken Wesson <kwesson@gmail.com> - 2011-02-08 20:40 +0100

csiph-web