class - Implementing Comparable in java 1.4.2 -


i have java question. i'm trying implement comparable in class. based on research, statement class be:

public class proeitem implements comparable<proeitem> {     private string name;     private string description;     private string material;     private int bomqty;  // other fields, constructors, getters, & setters redacted      public int compareto(proeitem other) {         return this.getname().compareto(other.getname());         } }// end class proeitem 

however, compile error { expected after comparable in class declaration. believe because i'm stuck java 1.4.2 (yes, it's sadly true).

so tried this:

   public class proeitem implements comparable {         private string name;         private string description;         private string material;         private int bomqty;      // other fields, constructors, getters, & setters redacted          public int compareto(proeitem other) {             return this.getname().compareto(other.getname());             }     }// end class proeitem 

without proeitem after comparable, compile error this:

"proeitem not abstract , not override abstract method compareto(java.lang.object) in java.lang.comparable public class proeitem implements comparable {" 

so question doing wrong implement comparable in 1.4.2? thank you.

your compareto() method should take object , should cast proeitem inside method.`

public int compareto(object other) {         return this.getname().compareto(((proeitem)other).getname());         } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -