Not sure if the offer was only open to OP but I'll bite. How about Java?
Not sure if the offer was only open to OP but I'll bite. How about Java?
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.
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.
Integer.valueOf(5) == Integer.valueOf(5)
true
Integer.valueOf(200) == Integer.valueOf(200)
falseYou don't compare non-primitives (which boxed integers are) with == in Java, you use the equals method.
And in fact when I googled to find the exact range where it switches from cached integers to truly creating new objects, the top link was at best highly misleading. https://www.tutorialspoint.com/check-two-numbers-for-equalit...
Obviously Java doesn't have the luxury of that decision at this point. But a lot of goofy parts of languages are string of fairly rational choices with unintended consequences.
If you want a instance, I recommend new :)
Integer val1 = 5;
Integer val2 = 5;
Integer val3 = 200;
Integer val4 = 200;
will have you ending up with val1 and val2 being equal with ==, but val3 and val4 won't be.The general reply is 'you're holding it wrong', but that doesn't make it any less absurd. That's what the PHPers say about "123" < "456A" < "78" < "123".
Unless you call `new` there's no guarantee that you have a different object.