Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #3041
| 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 | 2011-04-12 01:07 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <io01kh$rlk$1@dont-email.me> (permalink) |
| References | (2 earlier) <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> |
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