Java generics issue: Class “not within bounds of type-variable” error.

In MySearchTree the K of the base type is Course. So K must “extend” Comparable<Keyable<Course>> & Keyable<Course>. But it doesn’t, it extends Comparable<Keyable<DataElement>> & Keyable<DataElement>.

I guess DataElement should be generified in a similar manner to Comparable or Enum.

public interface Keyable <T> {public String getKey();}

public interface DataElement<THIS extends DataElement<THIS>> extends Comparable<Keyable<THIS>>, Keyable<THIS>, Serializable {...}
public class Course implements DataElement<Course> {...}


public interface SearchTree<K extends Comparable<Keyable<K>> & Keyable<K>> extends Serializable {...}
public class MySearchTree implements SearchTree<Course> {

Leave a Comment