Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #3041
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Novice to Generics Trying to Implement a Generic Priority Queue |
| Date | Tue, 12 Apr 2011 01:07:47 +0200 |
| Organization | A noiseless patient Spider |
| Lines | 39 |
| Message-ID | <io01kh$rlk$1@dont-email.me> (permalink) |
| References | <95a0645f-5c83-4028-8d82-259f83e45159@k9g2000yqi.googlegroups.com> <jbl0q6p0rcaa3olndpqe7r10qtij1joatt@4ax.com> <25ad9459-6d49-4f16-8eb9-d40bec3fc2e2@p13g2000yqh.googlegroups.com> <generic-array-20110411195050@ram.dialup.fu-berlin.de> <138ac7bc-69e3-458b-a49f-881ac1a7bfa5@k11g2000yqc.googlegroups.com> <invlj0$ibd$1@dont-email.me> <alpine.DEB.2.00.1104112240430.2081@urchin.earth.li> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Mon, 11 Apr 2011 23:08:01 +0000 (UTC) |
| Injection-Info | mx01.eternal-september.org; posting-host="r0VYSKUYIzh55s1uZ1A/eA"; logging-data="28340"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lMKXNqE3Thc82hvtltcjf" |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 |
| In-Reply-To | <alpine.DEB.2.00.1104112240430.2081@urchin.earth.li> |
| Cancel-Lock | sha1:w8ncu0z/vMWWyFTC0yeKw7bM4t0= |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3041 |
Show key headers only | View raw
On 11/04/2011 23:41, Tom Anderson allegedly wrote:
> On Mon, 11 Apr 2011, Daniele Futtorovic wrote:
>
>> On 11/04/2011 21:10, KevinSimonson allegedly wrote:
>>> On Apr 11, 11:52 am, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
>>>> KevinSimonson<kvnsm...@hotmail.com> writes:
>>>>> Exception in thread "main" java.lang.ClassCastException:
>>>>> [Ljava.lang.Object; cannot be cast to [Ljava.lang.Comparable;
>>>>
>>>> ( Da[] )new java.lang.Comparable[ size ]
>>>
>>> Stefan, thanks! That solved the problem and my program works just
>>> fine now.
>>
>> This might be somewhat OK in this case, but it's hardly advisable.
>>
>> A Comparable[] /is not a/ Da[].
>>
>> You'd normally pass the Class object around in such cases:
>>
>> public PriorityQueue( Class<Da> component, int size )
>> throws BadSizeException
>> {
>> if (0<= size)
>> { queue = (Da[]) Array.newInstance( component, size );
>
> I'm not sure about 'normally'. That is certainly a known technique (for
> those who haven't seen it, this use of a Class is called a 'type token'),
> and whilst it may be advisable, i don't think it's more common than making
> an array of some suitable static type and casting it uncheckedly [sic].
> Does the JDK use [hic] anywhere?
None that I'd know of. Some hackingry [sob] to overcome type erasure,
yeah, but nothing so outright type-unsafy [ham] as that.
--
DF.
An escaped convict once said to me:
"Alcatraz is the place to be"
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
Novice to Generics Trying to Implement a Generic Priority Queue KevinSimonson <kvnsmnsn@hotmail.com> - 2011-04-07 16:03 -0700
Re: Novice to Generics Trying to Implement a Generic Priority Queue markspace <-@.> - 2011-04-07 17:32 -0700
Re: Novice to Generics Trying to Implement a Generic Priority Queue KevinSimonson <kvnsmnsn@hotmail.com> - 2011-04-08 14:55 -0700
Re: Novice to Generics Trying to Implement a Generic Priority Queue markspace <-@.> - 2011-04-08 15:54 -0700
Re: Novice to Generics Trying to Implement a Generic Priority Queue Lew <noone@lewscanon.com> - 2011-04-08 20:39 -0400
Re: Novice to Generics Trying to Implement a Generic Priority Queue Tom Anderson <twic@urchin.earth.li> - 2011-04-09 10:36 +0100
Re: Novice to Generics Trying to Implement a Generic Priority Queue Roedy Green <see_website@mindprod.com.invalid> - 2011-04-09 05:50 -0700
Re: Novice to Generics Trying to Implement a Generic Priority Queue KevinSimonson <kvnsmnsn@hotmail.com> - 2011-04-11 08:08 -0700
Re: Novice to Generics Trying to Implement a Generic Priority Queue markspace <-@.> - 2011-04-11 10:29 -0700
Re: Novice to Generics Trying to Implement a Generic Priority Queue KevinSimonson <kvnsmnsn@hotmail.com> - 2011-04-11 12:10 -0700
Re: Novice to Generics Trying to Implement a Generic Priority Queue Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-04-11 21:42 +0200
Re: Novice to Generics Trying to Implement a Generic Priority Queue Tom Anderson <twic@urchin.earth.li> - 2011-04-11 22:41 +0100
Re: Novice to Generics Trying to Implement a Generic Priority Queue Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-04-12 01:07 +0200
csiph-web