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

Path csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Daniele Futtorovic <da.futt.news@laposte.net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: limitations on using enum as generic parameter
Date Tue, 08 Feb 2011 20:47:31 +0100
Organization A noiseless patient Spider
Lines 26
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>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Tue, 8 Feb 2011 19:47:30 +0000 (UTC)
Injection-Info mx01.eternal-september.org; posting-host="/vAN9LwPLXAylUBw+QRt4g"; logging-data="10665"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+n/KXY7rmuVX2J1eQH7pp6"
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7
In-Reply-To <4d519c14$1@news.x-privat.org>
Cancel-Lock sha1:SmltxkMJxbtGQ/5GTJ8rfNlXYH8=
Xref csiph.com comp.lang.java.programmer:25978

Show key headers only | 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