比较泛型类型 Java

2022-01-25 types compare java generics

我在比较泛型类型时遇到了问题.在 C# 中,我总是这样做: class Element<T, V>其中 T : IComparable.

I have a problem with comparing generic types. In C# I've always done something like: class Element<T, V> where T : IComparable<T>.

我的问题是如何用java编写?

My question is how can it be written in java?

推荐答案

我怀疑你想要类似的东西:

I suspect you want something like:

class Element<T extends Comparable<T>>

... 使用 Comparable 接口和一个 有界类型参数.

相关文章