Any reason that the following is not allowed?
HashMap<long, long> x = new HashMap<>();
you're using primitives rewrite to HashMap<Long,Long> x = new HashMap<>()
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With