top | item 37354637

(no title)

nathanwh | 2 years ago

> Name a language and I'll tell you a much worse issue.

Not sure if the offer was only open to OP but I'll bite. How about Java?

discuss

order

pkolaczk|2 years ago

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.

IshKebab|2 years ago

I haven't used Java for some time, but when I did it didn't have non-nullable types. I think collections were also type erased which is pretty bad.

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

Boxed Integers will compare with == for values -128 to 127 but not other valid ints.

    Integer.valueOf(5) == Integer.valueOf(5)
    true

    Integer.valueOf(200) == Integer.valueOf(200)
    false

chaosite|2 years ago

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.

paulddraper|2 years ago

.valueOf() will sometimes give different instance, sometimes not.

If you want a instance, I recommend new :)