1. Java does not allow to implement new interfaces for classes without modifying their signature - much more limiting than Rusts foreign trait rule. You cannot make a foreign class implement your new interface.
2. Java does not allow to create wrappers without incurring a significant memory overhead. A wrapper will consume at least 32 bytes of memory on 64-bit systems just for itself, when in Rust this can be 0.
3. Even if you define a wrapper, it would be way less ergonomic than in Rust - there is nothing like AsRef / Deref / From / Into etc machinery in Java.
That's a quirk of the language, sure, but it's barely an issue, and definitely not a worse issue. Don't get many wrong, Java has many issues, but this barely qualifies.
You don't compare non-primitives (which boxed integers are) with == in Java, you use the equals method.
pkolaczk|2 years ago
2. Java does not allow to create wrappers without incurring a significant memory overhead. A wrapper will consume at least 32 bytes of memory on 64-bit systems just for itself, when in Rust this can be 0.
3. Even if you define a wrapper, it would be way less ergonomic than in Rust - there is nothing like AsRef / Deref / From / Into etc machinery in Java.
IshKebab|2 years ago
JNI is a nightmare.
Strings are UTF-16.
Dealing with installing the JVM, whatever the hell "classpath" is, tweaking GC parameters etc. is a big downside.
Despite that it's definitely one of the saner languages out there.
monocasa|2 years ago
chaosite|2 years ago
You don't compare non-primitives (which boxed integers are) with == in Java, you use the equals method.
paulddraper|2 years ago
If you want a instance, I recommend new :)