java - Issue with <T extends Comparable<? super T>> -


I have a heap interface, and a heap class that has array-based implementation. I'm trying to pile up Class Integers, but I'm getting the following error:

  Exceptions in the thread "main" java.lang.ClassCastException: [Ljava.lang.Object; [Ljava.lang.Comparable] can not be cast into; In Hepare & Lt; Init & gt; (Hepyre.java) in Hepare. & Lt; Init & gt; (Heparre.Java 10) test.main (test.java))  

I will announce the announcement of each category, constructor and test method, whose expectation arises in the hope, The error can explain ...

  Public Interface Heap Interface & lt; T comparison & lt; Super T & gt; & Gt; {...} Public Classroom Hack & lt; T comparative & lt; Is expanded? Super T & gt; & Gt; Heap interface applies & lt; T & gt; {Private T [] Heap; Personal fixed final complete DEFAULT_CAPACITY = 10; Private int number of operants; Public Hippie () {This (DEFAULT_CAPACITY); } // and the default constructor public capability {numberOfEntries = 0; @SuppressWarnings ("uncheck") t [] tempHeap = (t []) new object [capability]; Pile = tempHeap; } // Alternate Constructor ...} Public Class Test {Public Stable Zero Main (String [] Args) {Hep Interface & lt; Integer & gt; H = new heparagne & lt; Integer & gt; (); For (int i = 0; i & lt; 16; i ++) h. Ed (i); Println (h); }}  

Any ideas?

You can not cast an object [] to t [] stating that as a T object Comparable is not comparable. Try making a comparative [] and assign it to a T [] :

  T [] tempHeap = (T []) new Try to compare [ability];  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -