<tfoot id='F1IYn'></tfoot>

    <legend id='F1IYn'><style id='F1IYn'><dir id='F1IYn'><q id='F1IYn'></q></dir></style></legend>

    • <bdo id='F1IYn'></bdo><ul id='F1IYn'></ul>

      <i id='F1IYn'><tr id='F1IYn'><dt id='F1IYn'><q id='F1IYn'><span id='F1IYn'><b id='F1IYn'><form id='F1IYn'><ins id='F1IYn'></ins><ul id='F1IYn'></ul><sub id='F1IYn'></sub></form><legend id='F1IYn'></legend><bdo id='F1IYn'><pre id='F1IYn'><center id='F1IYn'></center></pre></bdo></b><th id='F1IYn'></th></span></q></dt></tr></i><div id='F1IYn'><tfoot id='F1IYn'></tfoot><dl id='F1IYn'><fieldset id='F1IYn'></fieldset></dl></div>

      <small id='F1IYn'></small><noframes id='F1IYn'>

      什么是具体泛型?它们如何解决类型擦除问题,为什么不进行重大更改就不能添加它们?

      What are Reified Generics? How do they solve Type Erasure problems and why can#39;t they be added without major changes?(什么是具体泛型?它们如何解决类型擦除问题,为什么不进行重大更改就不能添加它们?)
      <legend id='v8cJF'><style id='v8cJF'><dir id='v8cJF'><q id='v8cJF'></q></dir></style></legend>
    1. <i id='v8cJF'><tr id='v8cJF'><dt id='v8cJF'><q id='v8cJF'><span id='v8cJF'><b id='v8cJF'><form id='v8cJF'><ins id='v8cJF'></ins><ul id='v8cJF'></ul><sub id='v8cJF'></sub></form><legend id='v8cJF'></legend><bdo id='v8cJF'><pre id='v8cJF'><center id='v8cJF'></center></pre></bdo></b><th id='v8cJF'></th></span></q></dt></tr></i><div id='v8cJF'><tfoot id='v8cJF'></tfoot><dl id='v8cJF'><fieldset id='v8cJF'></fieldset></dl></div>
      • <bdo id='v8cJF'></bdo><ul id='v8cJF'></ul>
          <tbody id='v8cJF'></tbody>
            1. <tfoot id='v8cJF'></tfoot>

              • <small id='v8cJF'></small><noframes id='v8cJF'>

              • 本文介绍了什么是具体泛型?它们如何解决类型擦除问题,为什么不进行重大更改就不能添加它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我已阅读 Neal Gafter 的 博客主题,但在许多方面仍不清楚.

                I've read Neal Gafter's blog on the subject and am still unclear on a number of points.

                在 Java、JVM 和现有集合 API 的当前状态下,为什么不能创建保留类型信息的集合 API 实现?难道这些不能以保留向后兼容性的方式替换 Java 未来版本中的现有实现吗?

                Why is it not possible to create implementations of the Collections API that preserve type information given the current state of Java, the JVM and existing collections API? Couldn't these replace the existing implementations in a future version of Java in a way where backwards compatibility is preserved?

                举个例子:

                List<T> list = REIList<T>(T.Class);
                

                REIList 是这样的:

                Where REIList is something like this:

                public REIList<T>() implements List {
                  private Object o;
                  private Class klass;
                
                  public REIList(Object o) {
                    this.o = o;
                    klass = o.getClass();
                  }
                ... the rest of the list implementation ...
                

                并且方法使用Object o和Class klass来获取类型信息.

                And the methods use Object o and Class klass to get the type information.

                为什么保留通用类信息需要更改语言,而不仅仅是更改 JVM 实现?

                Why would preserving generic class information require language changes rather than just a JVM implementation change?

                我不明白什么?

                推荐答案

                重点是,编译器中的具体泛型支持保留类型信息,而类型擦除泛型不支持.AFAIK,首先进行类型擦除的全部意义在于实现向后兼容性(例如,较低版本的 JVM 仍然可以理解泛型类).

                The whole point is that reified generics have support in the compiler for preserving type information, whereas type erased generics don't. AFAIK, the whole point of having type erasure in the first place was to enable backwards compatibility (e.g. lower versioned JVMs could still understand generic classes).

                您可以像上面那样在实现中显式添加类型信息,但是每次使用列表时都需要额外的代码,而且我认为这很混乱.此外,在这种情况下,除非您自己添加检查,否则您仍然没有对所有列表方法进行运行时类型检查,但是具体化的泛型将确保运行时类型.

                You can explicitly add the type information in the implementation, as you have above, but that requires additional code every time the list is used, and is pretty messy in my opinion. Also, in this case, you still don't have runtime type checking for all of the list methods unless you add the checks yourself, however reified generics will ensure the runtime types.

                这篇关于什么是具体泛型?它们如何解决类型擦除问题,为什么不进行重大更改就不能添加它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Bytecode features not available in the Java language(Java 语言中不可用的字节码功能)
                ClassCastException because of classloaders?(ClassCastException 因为类加载器?)
                How can I add a Javaagent to a JVM without stopping the JVM?(如何在不停止 JVM 的情况下将 Javaagent 添加到 JVM?)
                Cannot load 64-bit SWT libraries on 32-bit JVM ( replacing SWT file )(无法在 32 位 JVM 上加载 64 位 SWT 库(替换 SWT 文件))
                Encourage the JVM to GC rather than grow the heap?(鼓励 JVM 进行 GC 而不是增加堆?)
                Why a sawtooth shaped graph?(为什么是锯齿形图形?)

                <i id='b6PjL'><tr id='b6PjL'><dt id='b6PjL'><q id='b6PjL'><span id='b6PjL'><b id='b6PjL'><form id='b6PjL'><ins id='b6PjL'></ins><ul id='b6PjL'></ul><sub id='b6PjL'></sub></form><legend id='b6PjL'></legend><bdo id='b6PjL'><pre id='b6PjL'><center id='b6PjL'></center></pre></bdo></b><th id='b6PjL'></th></span></q></dt></tr></i><div id='b6PjL'><tfoot id='b6PjL'></tfoot><dl id='b6PjL'><fieldset id='b6PjL'></fieldset></dl></div>
              • <tfoot id='b6PjL'></tfoot>
              • <legend id='b6PjL'><style id='b6PjL'><dir id='b6PjL'><q id='b6PjL'></q></dir></style></legend>
                  <tbody id='b6PjL'></tbody>

                  • <small id='b6PjL'></small><noframes id='b6PjL'>

                      • <bdo id='b6PjL'></bdo><ul id='b6PjL'></ul>