[英]Java "Type parameter X is not within its bound; should implement Comparable<X>" (LocalDateTime as key in map)
I have implemented my own Map called AVLTreeMap.我已经实现了我自己的名为 AVLTreeMap 的地图。 Here is the class signature.这是类签名。
public class AVLTreeMap<K extends Comparable<K>, V>
As you can see, I am using comparable keys in this map.如您所见,我在此地图中使用了可比较的键。 The problem is that I want to instantiate a map with a LocalDateTime
type key.问题是我想用LocalDateTime
类型的键实例化一个地图。
private AVLTreeMap<LocalDateTime, CallRecord> callRecords;
I am getting the error Type parameter 'java.time.LocalDateTime' is not within its bound; should implement 'java.lang.Comparable<java.time.LocalDateTime>'
我收到错误Type parameter 'java.time.LocalDateTime' is not within its bound; should implement 'java.lang.Comparable<java.time.LocalDateTime>'
Type parameter 'java.time.LocalDateTime' is not within its bound; should implement 'java.lang.Comparable<java.time.LocalDateTime>'
. Type parameter 'java.time.LocalDateTime' is not within its bound; should implement 'java.lang.Comparable<java.time.LocalDateTime>'
。
As far as I can tell, LocalDateTime implements Comparable<ChronoLocalDateTime<?>>
and at this point, I am pretty confused as to how I can create my map with a LocalDateTime
key set.据我所知, LocalDateTime 实现了Comparable<ChronoLocalDateTime<?>>
,此时,我对如何使用LocalDateTime
键集创建地图感到非常困惑。
Any ideas?有任何想法吗?
Your generic signature for a Comparable
is a little off, this你对Comparable
通用签名有点不对,这个
public class AVLTreeMap<K extends Comparable<K>, V>
Should be something like应该是这样的
public class AVLTreeMap<K extends Comparable<? super K>, V>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.