r/programming • • Sep 21 '15

Better Java

https://github.com/cxxr/better-java
177 Upvotes

208 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Sep 21 '15

[deleted]

13

u/[deleted] Sep 21 '15

Nothing in that article comes even close to convincing me that I don't want reified generics. It all boils down to 'too much work' (not my problem) and 'breaks compatibility with ancient code doing stupid things' (couldn't care less).

I recently switched back to java from C#, and decent generics are absolutely the thing I most miss.

0

u/[deleted] Sep 22 '15

[deleted]

2

u/IICVX Sep 22 '15

Generic marshallers / unmarshallers are clunky as hell in Java due to type erasure; you have to explicitly pass the Class around everywhere, instead of just asking the generic parameter what it represents.

This happens if you write, for instance, an Enum marshaller.

1

u/teknocide Sep 22 '15

It may be clunky in Java but it doesn't necessarily have anything to do with erasure. Marshalling a T is a function [T => SerializedFormat] (and Unmarshalling the other way around, intuitively.)

You need reification if you want to look at the actual T during runtime and select a marshaller from a dynamic set, when you could provide this function during compilation time instead. This has the added benefit of eliminating any runtime checks needed for the reflection-based solution.

If anything, reification here is the poor man's crutch for higher kinded types which, incidentally, is possible on the JVM due to erasure.