关于 Java 中的具体化泛型有什么说法吗?
我知道这个问题可能会引发更多的讨论,而不是具体的答案(我知道这并不可取)。但随着 Oracle 最近的收购,我想知道是否有任何消息称 Java 可能(有一天)获得具体化泛型?我听说 Oracle 想要给 Java 带来一点推动,我想不出更好的办法了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一篇关于具体化泛型讨论的好文章,这里< /a>,您应该阅读有关 Java 的内容。基本上它概述了引入此类更改可能会发生的一些陷阱。仔细想想,这对于向后兼容性来说是相当残酷的。如果您想知道它来自哪里,请在黑客新闻上找到它。
感谢有人谈论 添加Java 的闭包。不再需要费力地只使用诸如 Functional Java 之类的东西(并不是说这些不好,相反.)
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.)
我不知道 Java 7 之外的未来,但看起来 Reified Generics 不会” t 在 Java 7 中(如果 Oracle 想要给 Java 带来一点推动力,他们应该开始随着 Java 7 的发布)。
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).
与几乎所有人的看法相反,具体化泛型在 Java 中是可能的,这意味着可以避免类型擦除。事实上,如果你愿意的话,这是一个诡计或纯粹的黑魔法。
写了一篇关于此的文章
我在 http://rgomes-info.blogspot.co.uk/2013/12/using-typetokens-to-retrieve-generic.html
在文章的最后有一节介绍了这个技巧的优点和缺点。
实际上,正确的做法是在 Java 中“正确”具体化泛型,而不是像这样的技巧……但不幸的是事实并非如此。
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.