Reputation: 2652
Any reason that the following is not allowed?
HashMap<long, long> x = new HashMap<>();
Upvotes: 11
Views: 30653
Reputation: 4584
Using standard collections for primitive types like long is not really effective
If you need to minimize memory footprint and get better performance you should consider 3rd-party collection libraries like Trove
Upvotes: 5
Reputation: 587
In Java, types with generic type parameters, such as HashMap, only accept types that inherit from Object. long does not inherit from Object, so you can't use it with HashMap. You can however use Long, which is a boxed version of long.
Upvotes: 8
Reputation: 28559
you're using primitives rewrite to HashMap<Long,Long> x = new HashMap<>()
Upvotes: 14