关于 Java 中的具体化泛型有什么说法吗?

发布于 2024-09-11 12:35:24 字数 132 浏览 6 评论 0原文

我知道这个问题可能会引发更多的讨论,而不是具体的答案(我知道这并不可取)。但随着 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

祁梦 2024-09-18 12:35:24

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.)

老子叫无熙 2024-09-18 12:35:24

我不知道 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).

窝囊感情。 2024-09-18 12:35:24

与几乎所有人的看法相反,具体化泛型在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文