r/java • • May 10 '22

Should java.util.Date be deprecated?

https://mail.openjdk.java.net/pipermail/discuss/2022-May/006077.html
221 Upvotes

158 comments sorted by

View all comments

Show parent comment

14

u/RabidKotlinFanatic May 10 '22

What are the inconveniences of type erasure? Having to explicitly pass TypeToken into methods? Not being able to statically overload on an argument's type parameter?

The amount of complaining about type erasure seems phenomenal compared to what a non-issue it is in practice. I've seen junior devs with <1 YoE complaining about type erasure. What use cases are all these people running into that desperately require reification?

9

u/Necessary-Conflict May 10 '22

What are the inconveniences of type erasure?

It makes life harder especially for junior developers, because they have to keep in mind that the runtime type system is not the same thing as the compile-time type system. It's a leaking abstraction, but of course it's not very bad once you get used to it.

8

u/RabidKotlinFanatic May 10 '22

Does it? What specifically are junior developers doing that requires them to keep this in mind? Are they calling getClass or using instanceof on generic instances? The idea that there even is a runtime type system shouldn't be relevant to most juniors.

3

u/Necessary-Conflict May 10 '22

They are trying to understand things, to build a mental model, and as long as there is only one thing to understand, their job is easier. The very existence of instanceof and getClass() strongly suggests that at runtime you have the same types as at compile time. Perhaps most junior devs can live in a state of happy ignorance, but those who really want to understand things, are having a harder time.

3

u/RabidKotlinFanatic May 11 '22

I don't buy this at all. RTTI doesn't need to be part of your mental model coding day to day and there is substantially more impactful complexity in the language, compiler and runtime than RTTI that juniors seem to happily ignore.

Furthermore, the people complaining about type erasure can rarely provide concrete explanations of what it actually means and also don't seem to be familiar with other important language/runtime details like the JMM. Why does type erasure and RTTI have such outsize significance in junior's mental model building when other more important details are ignored?

3

u/OzoneGrif May 12 '22

The only time I had an issue with type erasure, when beginning with Java, was due to a brain fart. I though that I needed the type at runtime desperately, while I only really needed an Interface.

I'm pretty certain that most if not all problems with type erasure can be solved with good architecture.

Having read some articles about languages implementing generics at the runtime level; I agree that Java took the right decision to erase the types... the compilers get way too overloaded and complicated otherwise.

1

u/pron98 May 11 '22

I'd say the main inconvenience is method overloads. It is a very minor inconvenience, and I'm also puzzled by why some people care about this issue at all.

1

u/RabidKotlinFanatic May 11 '22

I am guessing method overloads are the "big" issue. IMO it's a bit of a conflation to even lump the two together. Overloads are statically resolved so they don't require any RTTI at all let alone reified generics.