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

<tfoot id='pqwF4'></tfoot>
    • <bdo id='pqwF4'></bdo><ul id='pqwF4'></ul>

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

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

      1. 为什么不能分配 I &lt;?扩展类型>到&lt;类

        时间:2023-07-27

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

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

            <bdo id='k9JAo'></bdo><ul id='k9JAo'></ul>
                <tbody id='k9JAo'></tbody>
              <legend id='k9JAo'><style id='k9JAo'><dir id='k9JAo'><q id='k9JAo'></q></dir></style></legend>
                <tfoot id='k9JAo'></tfoot>

                  本文介绍了为什么不能分配 I &lt;?扩展类型>到&lt;类型&gt;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  以下陈述:

                  URLClassLoader ucl = (URLClassLoader) ClassLoader.getSystemClassLoader();
                  Class<URLClassLoader> uclc = ucl.getClass();
                  

                  因错误而失败:

                  Type mismatch: cannot convert from Class<capture#2-of ? extends URLClassLoader> to Class<URLClassLoader>
                  

                  这里为什么需要演员表?

                  Why do I need a cast, here?

                  我发现了几篇文章解释了为什么你不能做相反的事情(将 T 分配给 a ),但这(有点)显而易见并且可以理解.

                  I found several posts explaining why You can't do the reverse (assign T to a ), but that's (kind of) obvious and understood.

                  注意:我是在 eclipse Luna 下编写的,所以我不知道这是 Luna 的怪癖还是我真的不理解泛型.

                  NOTE: I am coding this under eclipse Luna, so I don't know if it's a Luna Quirk or if there's something I really dont understand in generics.

                  推荐答案

                  协变 vs 逆变 vs 不变

                  • 不变的.

                  因此,

                  不是 Class<URLClassLoader>

                  在 Java 中,变量可以保存对相同类型或子类型的实例的引用.

                  In Java a variable can hold a reference of an instance of same type or subtype.

                  因此,

                  Class<URLClassLoader> uclc = ucl.getClass();
                  

                  无效.

                  另一方面,

                  Class<? extends URLClassLoader> uclc = ucl.getClass();
                  

                  将是有效.

                  这篇关于为什么不能分配 I &lt;?扩展类型>到&lt;类型&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

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

                        <tbody id='Sqw3I'></tbody>
                      <tfoot id='Sqw3I'></tfoot>
                      <legend id='Sqw3I'><style id='Sqw3I'><dir id='Sqw3I'><q id='Sqw3I'></q></dir></style></legend>
                        <bdo id='Sqw3I'></bdo><ul id='Sqw3I'></ul>