我该如何解决这个问题?问题在代码中写为注释

时间:2014-03-05 20:21:51

标签: java

// This is java code 
//  it is saying comparable is a raw type, references to generic type comparable 
  <T> should be parameterized. I have never recieved this error before so I    
   don't know how to resolve the issue.  



package edu.swosu.wordcraft.timers;


    /** The base (and abstract) class for timer events */
    public abstract class Event implements Comparable {
protected long time;
 protected long delay;

/** Constructs new timer.  
 * This determines current system time and adds the appropriate 
       time based on the delay parameter. 
 * 
 * Note that this does not automatically add itself to the timer thread
 * 
 * @param delay     Delay for the timed event (in milliseconds) 
 */
public Event(long delay) {
    time = System.currentTimeMillis() + delay;
    this.delay = delay;
}

/** Implements Comparable interface - compares value of time parameter 
 * 
 */
public int compareTo(Object otherEvent) {
    if(!(otherEvent instanceof Event)) {
        //this really shouldn't happen
        throw new ClassCastException("Invalid Onject during Even compare");
    }

    long otherTime = ((Event)otherEvent).getTime(); 

    if (this.time > otherTime) {
        return 1;
    }
    else {
        if (this.time < otherTime) {
            return -1;
        }
        else {
            return 0;
        }
    }
}

public long getTime() {
    return time;
}

/** method to be called when timer fires
 *  
 */

public abstract void execute();
  }

1 个答案:

答案 0 :(得分:3)

基本上,它告诉您,您必须提供可以与实现Comparable的类进行比较的类。在您的情况下,如果您想将EventEvent进行比较,则只需编写

即可
implements Comparable<Event>