Any word on reified generics in Java?
Asked Answered
N

3

9

I know this question will probably provoke more discussion than concrete answers (which I know isn't preferable). But with the recent acquisition by Oracle, I was wondering if there's been any word that Java might (someday) get reified generics? I've heard that Oracle wants to give Java a bit of a boost, and I can think of no better way.

Nib answered 29/7, 2010 at 3:45 Comment(0)
C
4

There's a good article on the discussion of reified generics, here, that you should read in regards to Java. Basically it outlines some of the pitfalls that might happen with the introduction of such a change. It's fairly brutal for backwards compatibility when you think about it. Picked it up on Hacker News if you're wondering where it came from.

Be grateful that there's talk of adding closures to Java. No more having to slog through with only things like Functional Java and their ilk (not that these were bad, on the contrary.)

Chare answered 29/7, 2010 at 3:50 Comment(4)
Sigh... It's a good thing Sun/Oracle aren't in charge of building this nation's freeways. They'd mandate a horse-and-buggy lane at the expense of an express lane. (Sorry - I know it's not your fault. :-P)Nib
To steal an idea from douglas adams: adding closures to java is like painting a wheel to make it go faster.Cessionary
Adding closures to Java is like adding a steering wheel because people wanted to be able to easily turn their horse-and-buggy.Biocellate
@Mechanicalsnail I code in Scala. Haven't touched Java in 2 years. Never been happier.Chare
N
2

I don't know about the future beyond Java 7 but it looks like Reified Generics won't be in Java 7 (and if Oracle wants to give Java a bit of boost, they should start with releasing Java 7).

Nuri answered 29/7, 2010 at 3:52 Comment(0)
P
1

Contrary to what almost everyone believe, reified Generics is possible in Java, which means that type erasure can be avoided. Actually, it is a trick or pure dark magic if you will.

I've written an article on this at

http://rgomes-info.blogspot.co.uk/2013/12/using-typetokens-to-retrieve-generic.html

In the end of the article there's a section on pros and cons of this trick. Actually, the correct thing would be having "proper" reified Generics in Java and not a trick like this... but unfortunately this is not the case.

Poulard answered 14/1, 2011 at 6:30 Comment(1)
+1 because of the interesting article, but there is a whole class of things you could do with reified generics that you don't get from simply passing the type around. True reified generics are possible with a bit of code generation magic, and, given that asm is like the coolest thing ever, I can't explain why most people don't give it a go.Cessionary

© 2022 - 2024 — McMap. All rights reserved.