I have below code which compiles perfectly fine with maven but Intellij keeps on giving me error saying Inconvertible types can not cast 'K' to java.lang.Long
.
public class BPlusTree<K extends Comparable<K>, T> {
public void debug(K time) {
Long l = (Long) time;
}
}
When I remove the extends Comparable<K>
part from the class definition, intellij stops giving this error. What is happening here? I know this casting can throw a runtime ClassCastException
but why the compilation error?