[英]Why can I not create a HashMap with 'long' types in Java?
有什么理由不允许以下情况?
HashMap<long, long> x = new HashMap<>();
你正在使用原语重写为HashMap<Long,Long> x = new HashMap<>()
In Java, types with generic type parameters, such as HashMap, only accept types that inherit from Object. 在Java中,具有泛型类型参数的类型(例如HashMap)仅接受从Object继承的类型。 long does not inherit from Object, so you can't use it with HashMap.
long不从Object继承,因此您不能将它与HashMap一起使用。 You can however use Long, which is a boxed version of long.
但是你可以使用Long,它是long的盒装版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.