Results 1 to 3 of 3
Thread: Problem with compareTo() method
- 12-05-2013, 12:35 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 18
- Rep Power
- 0
Problem with compareTo() method
I have a generic class that contains a compareTo() method
I'm getting an error on the method it'self that goes something like;
Java Code:Name clash: the method compareTo(T) of type twos<T N> has the same erasure as compareTo(T) of type Compareable<T> but does not override it.
here's my class
Java Code:public class twos<P,N> implements Comparable<twos<P,N>>{ private P a; private N b; } public twos(P puu, N paa ){ a=puu; b=paa;} public P getP(){ return a;} public N getN(){ return b;} public compareTo(P bee){ int num1 = ((Comparable<twos<P, N>>) this.a).compareTo( (twos<P, N>) bee.b ); if (num1 != 0) return num1; if (this.a < bee.a) return -1; if (this.a > bee.a) return 1; return 0; } } }//end of class
Any help is appreciated
- 12-05-2013, 12:45 PM #2
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 12
Re: Problem with compareTo() method
Check out the two typecasts you do on line 13; notice a difference?
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 12-05-2013, 05:13 PM #3
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 13
Re: Problem with compareTo() method
What exactly are you trying to do here? The comparable interface is:
Java Code:interface Comparable<T> { public int compareTo<T o> }
don't understand either of your casts for types P a or N b. Do they also have their own Comparable interface implementations?
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
compareTo method
By Tabula Rasa in forum New To JavaReplies: 4Last Post: 04-21-2011, 05:49 PM -
Doubt About CompareTo method() ?
By makpandian in forum New To JavaReplies: 8Last Post: 03-08-2011, 07:19 AM -
using the compareTo method
By anonymous445 in forum New To JavaReplies: 3Last Post: 01-19-2011, 04:53 AM -
need help wit this compareTo method
By ShinTec in forum New To JavaReplies: 4Last Post: 02-02-2010, 03:24 AM -
ArrayLists compareTo method, equals method
By random0munky in forum New To JavaReplies: 2Last Post: 10-26-2009, 08:20 PM
Bookmarks