在Java泛型的情况下,向后兼容究竟意味着什么? [英] What exactly is meant by backwards compatibility in case of Java Generics?
问题描述
完全兼容的原因在这里呢?还有在某些情况下可用的泛型类型信息,还是总是无法获得,除了向后兼容性还有其他原因吗?
我有一些关于它的知识,但我想如果有人愿意回答这个问题,终于明白了。我已经阅读了几篇文章和Oracle文档,但他们并没有把注意力放在我想要解决的问题上。
>类型信息始终删除。假设你有一组字符串,你可以(现在)使用 What exactly compatibility reasons mean here? Also is generic type information available in some cases or is it ALWAYS unavailavble and are there any other reasons than backwards compatibility? I have some knowledge about it but I would like to finally understand it if anyone would be kind enough to answer this question. I have read read several articles and bits of Oracle documentation but they weren't focused on the problem I'm trying to figure out here. Type information is always erased. Imagine you have a set of strings, you would (now) use 这篇关于在Java泛型的情况下,向后兼容究竟意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Set
- 但是在添加泛型之前,它将简单地为 Set
。为了确保将泛型添加到Java(2004年使用J2SE 5.0)时的向后兼容性,类型信息将被删除。所以
Set< String>
编译为 Set
以允许与添加泛型之前编写的代码的兼容性。 b $ bGeneric type information is not available at runtime in Java for backwards compatibility reasons.
Set<String>
- but before generics were added it would be simply Set
. To ensure backwards compatibility when generics were added to Java (in 2004 with J2SE 5.0) the type information is removed. So Set<String>
compiles to Set
to allow compatibility with code written before generics were added.