I have a java interface called BST (short for binary search tree) which has generic types Key,Value where Key extends Comparable.I defined it as below.
public interface BST<Key extends Comparable<Key>,Value> {
public void put(Key key,Value value);
public Value get(Key key);
public void delete(Key key);
public Iterable<Key> keys();
}
Now I want to define an implementation of the above interface.I tried this
public class BSTImpl<Key extends Comparable<Key> ,Value> implements BST<Key extends Comparable<Key>,Value> {
...
}
The above definition causes an error message in eclipse IDE ..The extends
token after implements BST<Key
seems to be the culprit
Syntax error on token "extends", , expected
If I omit the "extends" token from the definition (as given below),the error goes away, and I can get eclipse to generate the unimplemented methods correctly
public class BSTImpl<Key extends Comparable<Key> ,Value> implements BST<Key ,Value> {
@Override
public void put(Key key, Value value) {
// TODO Auto-generated method stub
}
@Override
public Value get(Key key) {
// TODO Auto-generated method stub
return null;
}
@Override
public void delete(Key key) {
// TODO Auto-generated method stub
}
@Override
public Iterable<Key> keys() {
// TODO Auto-generated method stub
return null;
}
}
Why does the extends token cause an error in the first place? can someone please explain?