i'm working with BST data structure and i have a class called TimeInterval
private TimeInterval StartTime,EndTime;
public TimeInterval(Time time,Time time2){
    StartTime = (TimeInterval) time; //cannot convert from Time to TimeInterval
    EndTime = (TimeInterval) time2; //cannot convert from Time to TimeInterval
}
@Override
public int compareTo(TimeInterval that) {
    if (StartTime.compareTo(that.EndTime) > 0) {
        return 1;
    }
    if (EndTime.compareTo(that.StartTime) < 0) {
        return -1;
    }
    return 0;
}
What can i do to fix this problem and let the method compareTo work fine? NOTE : i've tried to do this and it didn't work :
private Time StartTime,EndTime;
public TimeInterval(Time time,Time time2){
    StartTime =  time;
    EndTime =  time2;
}
@Override
public int compareTo(TimeInterval that) {
    if (((TimeInterval)StartTime).compareTo((TimeInterval)that.EndTime) > 0) {
        return 1;
    }
    if (((TimeInterval)EndTime).compareTo((TimeInterval)that.StartTime) < 0) {
        return -1;
    }
    return 0;
}
 
    