开发者

Comparable and generics

开发者 https://www.devze.com 2023-02-27 11:41 出处:网络
When this class is created.. public static class TreeNode<E extends Comparable<E>> 开发者_运维知识库what does the <E extends Comparable<E>> mean?That is a generic constraint

When this class is created..

public static class TreeNode<E extends Comparable<E>>

开发者_运维知识库what does the <E extends Comparable<E>> mean?


That is a generic constraint.

It means that whatever type you store in the TreeNode must implement the Comparable<E> interface.


It means that whenever you create an instance of this class like

TreeNode<MyClass> myTreeNode = new TreeNode<MyClass>();

MyClass must implement Comparable < MyClass >

public class MyClass implements Comparable<MyClass>
{
      //CODE
}
0

精彩评论

暂无评论...
验证码 换一张
取 消