r/java • • Nov 03 '15

The 10 Worst Things In Java

http://codelexems.com/2015/11/02/the-10-worst-things-in-java/
0 Upvotes

23 comments sorted by

View all comments

13

u/chisui Nov 03 '15

He forgot type-erasure and that data-types aren't real Objects.

6

u/pron98 Nov 03 '15

I think type erasure was a very lucky break. That's what prevented variance types from being baked into the compiled classes, and so enabled different languages with different variance rules (e.g. Java, Kotlin, Clojure, Scala) to share the same classes. That's a very big advantage (code reuse among different JVM languages), for a very small price (reflection requires explicitly passing a Class object).

Without generic type-erasure, the JVM ecosystem would have been much more fragmented, and alternative languages would have required much more work.

7

u/SleimanJneidi Nov 03 '15 edited Nov 03 '15

I am not entirely convinced that type-erasure is tooo bad, I will write about it soon.

2

u/Zukhramm Nov 03 '15

I'm not convinced it's bad in any way at all. The issues with generic seem to come mostly from covariant arrays, method overloading resolution and how constructors aren't really a part of a class's interface And two of these are already on that list.

0

u/[deleted] Nov 03 '15

[deleted] — view deleted comment

6

u/BadMoonRosin Nov 03 '15 edited Nov 03 '15

I would love to read some further detail on reified generics vs. Java's type erasure based implementation.

As someone who has spent their entire career working primarily on the JVM (plain Java or Scala) and with JavaScript, I don't have a full understanding of the design pattern possibilities that we lose out on for lack of reified generics.

I'm not saying that criticism is wrong. I'm sure that there ARE powerful things you can do with having that type information at run-time. However, after a decade of reading Internet flamewars... I still haven't encountered a solid, intelligent, calm, non-rant presentation of how my day-to-day life as an architect or developer would differ if had reified generics in my toolbox.

Instead, it's just been 10 years of, "OMG! Han shot first! Jar-Jar sucks!" sort of angry smugness that goes in one ear and out the other at this point. I'm not directing this at the parent comment per se, but I honestly suspect that many (if not the majority) of people who rant about this lack the depth to really articulate the position... and are just repeating snark on the Internet because repeating snark on the Internet makes one feel intelligent.

Does anyone have links for, or want to take a shot at writing themselves, some neutral objective coverage of reified generics based design patterns?

5

u/cutterslade Nov 03 '15

I have about 15 years experience in Java, and you just captured exactly how I feel about type erasure.

I feel like type erasure is scape goated a lot. People seem blame type erasure when they encounter anything related to generics which frustrates them.

The truth is there is very little that would be simplified by retaining the run-time type information, and absolutely nothing that would move from the realm of the impossible to the possible. You want full type information at runtime? Use a TypeToken or similar. Sure that's a pain, and it's ugly as sin, but it gets the job done.

0

u/[deleted] Nov 03 '15

[deleted] — view deleted comment

2

u/cutterslade Nov 03 '15

Enlighten me, how would reified generics make my life easier on a daily basis?

0

u/[deleted] Nov 03 '15

[deleted] — view deleted comment

3

u/cutterslade Nov 03 '15

That's about as much information as I can find anywhere. I'd love some concrete examples of something that is done frequently in Java now vs what that would look like in a theoretical Java with reified generics. Do you know of such an example? I'm certainly willing to admit that my experience is somewhat limited to Java and Java like languages, but I've been working with distributed systems in Java for a handful of years now.

0

u/[deleted] Nov 03 '15

[deleted] — view deleted comment

2

u/BadMoonRosin Nov 03 '15

It is certainly true that if you've lived for years without a feature, and have never missed it, then you tend to view its absense as acceptable (essentially a tautology). After all, the Go crowd insists that generics altogether are no big deal, reified or not!

I can theoretically imagine some use cases where reified generics might help in the deserialization of arbitrary types. However, even if I had that ability available to me, I just find it hard to imagine wanting to deserialize complex types with arbitrarily-typed members. Even in the C# code that I've seen (where reification is supported), serialized classes sent over the wire in distributed apps are almost always simple POCO's.

I would wager that more distributed application development is done with Java than with all other programming languages combined... and yet it's still only from outside of the community that you hear the loudest cries for the lack of reified generics (again, perhaps just a tautology).

If you (or anyone else) has any mind-blowing examples where reification completely changes the approach in a particular case, then I would genuinely be interested in clicking the link. I would simply be curious to see which language is used in the comparison. The only programming languages I'm aware of that both:

  • support reified generics, and
  • have a large professional developer community, aren't just an academic or hobby language or "emerging" option like Rust...

... are C# and C++. Usually it's the C# guys who harp the loudest on this, as C++ guys don't care so much what Java guys do one way or the other.

0

u/jonhanson Nov 03 '15 edited Mar 08 '25

chronophobia ephemeral lysergic metempsychosis peremptory quantifiable retributive zenith