How is extending an interface legal in Java?

Comparable is defined as an interface. In that case, why is Key K extends Comparable<K> legal in the following case, and why isn't K implements Comparable<K> used instead?

public class Entry<K extends Comparable<K>, V> implements Comparable<Entry<K, V>> { ... }

This kind of code is used in ordered symbol tables for example.

Jon Skeet
people
quotationmark

Well, K could be an interface extending Comparable<K> instead of a class implementing it... in which case extends would be more suitable. As the declaration of Entry doesn't know whether K will be an interface type or a class type, it can't be right in every situation.

Ultimately this just gives simple and consistent syntax for expressing generic bounds without having to worry whether that upper bound is a class or an interface.

people

See more on this question at Stackoverflow