Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is an unchecked cast and how do I go about fixing it?

 
Samuel Arwood
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone. I'm back again, just now with this unchecked casting issue. I have never seen it before and all the google searches turn up code that is way beyond me. I'll post a snippet of the code giving me the problem and then the error the compiler gives me. Any help would be greatly appreciated. Thanks in advance.



and during compiling i get this message:


BinaryHeap.java:76: warning: [unchecked] unchecked cast
found : java.lang.Comparable[]
required: AnyType[]
array = (AnyType []) new Comparable[ newSize ];
 
Stephan van Hulst
Bartender
Pie
Posts: 4840
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, this is not gonna work.

You're using a raw type in your code, which is giving you the unchecked cast problem. You normally fix this by using a fully parameterized class instead: Comparable<Whatever>. In this case it's not gonna work though, because you can't create an array of a generic type. Comparable<Whatever>[] can not be instantiated.

Anyway, I'm not really getting what the point of casting an array of Comparable to an array of AnyType is. Why not just do array = new AnyType[newSize]; ?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic