Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Novice to Generics Trying to Implement a Generic Priority Queue Date: Thu, 07 Apr 2011 17:32:18 -0700 Organization: A noiseless patient Spider Lines: 31 Message-ID: References: <95a0645f-5c83-4028-8d82-259f83e45159@k9g2000yqi.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 8 Apr 2011 00:32:24 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="XKAhP57P670kPn+9QWHVAA"; logging-data="22412"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xNnu1BfIjeyuN+B0s/+gNZ4riU0xFHug=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: <95a0645f-5c83-4028-8d82-259f83e45159@k9g2000yqi.googlegroups.com> Cancel-Lock: sha1:nlkaYvr357O67LhG/rPSPYZXMCM= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2960 On 4/7/2011 4:03 PM, KevinSimonson wrote: > How would I implement a heap _without_ being able to declare an array > of the > type passed in? This is a bit of a flaw in Java's generics. The generic types aren't reifiable, so there's actually no type at run time for the JVM to use to create the array. Sometimes you can go around this limitation. Sometimes you can't. Here's the case for when you can't. @SupressWarnings("unchecked") queue = (Da[]) new Object[size]; Don't use SupressWarnings unless you have to, but in this case you have to. > > The rest of the compilation errors seem to be referring to my use of > method > "compareTo< Da>()". Can anyone tell me what I'm doing wrong here? Comparable is a bit of a weird one. With out going into details, you need "Comparable" on the class declaration to get the type right. I didn't read through the rest of your code, but hopefully this gets you pointed in the right direction.