简体   繁体   English

可比和通用

[英]Comparable and generics

When this class is created.. 创建此类时。

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

what does the <E extends Comparable<E>> mean? <E extends Comparable<E>>是什么意思?

That is a generic constraint. 这是一个通用约束。

It means that whatever type you store in the TreeNode must implement the Comparable<E> interface. 这意味着您存储在TreeNode中的任何类型都必须实现Comparable<E>接口。

It means that whenever you create an instance of this class like 这意味着每当您创建此类的实例时,例如

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

MyClass must implement Comparable < MyClass > MyClass必须实现Comparable <MyClass>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM