简体   繁体   English

Java“类型参数X不在其范围内;应该实现Comparable<X> &quot; (LocalDateTime 作为地图中的键)

[英]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.

相关问题 Java Generics - 类型参数`K`不在其范围内; 应该实施X. - Java Generics - Type parameter `K` is not within its bound; should implement X Java类型参数不在其范围内 - Java type parameter is not within its bound 类型参数“S”的红外类型“S”不在其范围内; 应该扩展&#39;java.lang.Integer&#39; - infrred type 'S' for type parameter 'S' is not within its bound ; should extend 'java.lang.Integer' 类型参数T不在其范围内; 应该扩展MyBaseClass - Type parameter T is not within its bound; should extend MyBaseClass 类型参数不在其范围内 - Type Parameter is not within its bound Java Generics问题:类型参数E不在其范围内 - Java Generics Question: type parameter E is not within its bound 类型参数“S”的推断类型“S”不在其范围内; 应该扩展'com.javatest.entity.User' - Inferred type 'S' for type parameter 'S' is not within its bound; should extend 'com.javatest.entity.User' 何时实施Comparable <super class of X> 而不是可比较的 <X> ? - When to implement Comparable<super class of X> instead of Comparable<X>? 关于使用Java泛型的错误:“类型参数S不在其范围内” - About error using Java generics: “type parameter S is not within its bound” 类型参数“S”的推断类型“S”不在其范围内; - inferred type 'S' for type parameter 'S' is not within its bound;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM