• <legend id='7DBmh'><style id='7DBmh'><dir id='7DBmh'><q id='7DBmh'></q></dir></style></legend>
  • <tfoot id='7DBmh'></tfoot>

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

      1. <small id='7DBmh'></small><noframes id='7DBmh'>

        Java 泛型在 Eclipse 中编译,但在 javac 中不编译

        Java generics compile in Eclipse, but not in javac(Java 泛型在 Eclipse 中编译,但在 javac 中不编译)

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

        2. <tfoot id='vidsC'></tfoot>

          <legend id='vidsC'><style id='vidsC'><dir id='vidsC'><q id='vidsC'></q></dir></style></legend>
              <bdo id='vidsC'></bdo><ul id='vidsC'></ul>

                  <tbody id='vidsC'></tbody>
                  本文介绍了Java 泛型在 Eclipse 中编译,但在 javac 中不编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我不得不发现我的项目中有 Java 代码,它在 Eclipse 中编译和运行良好,但在 javac 中引发编译错误.

                  I had to discover I have Java code in my project, which compiles and runs fine in Eclipse, but throws a compilation error in javac.

                  一个独立的片段:

                  import java.util.HashSet;
                  import java.util.Set;
                  
                  public class Main {
                  
                      public static void main(String[] args) {
                      Set<Integer> setOfInts = new HashSet<Integer>();
                      Set<Object> setOfObjects = covariantSet(setOfInts);
                      }
                  
                      public static <S, T extends S> Set<S> covariantSet(Set<T> set) {
                      return new HashSet<S>(set);
                      }
                  
                  }
                  

                  javac 中的编译返回:

                  Compilation in javac returns:

                  Main.java:10: incompatible types
                  found   : java.util.Set<java.lang.Integer>
                  required: java.util.Set<java.lang.Object>
                      Set<Object> setOfObjects = covariantSet(setOfInts);
                                                             ^
                  

                  此错误现在会阻止在 Maven 中构建项目.由于 Eclipse 编译器被构建为更宽容,我现在不得不假设上面的片段的定义和使用静态方法是无效的 Java?

                  This error now prevents building the project in Maven. As the Eclipse compiler is built to be more tolerant, I now have to assume the definition and usage of snippets as above static method is no valid Java?

                  推荐答案

                  好像Sun的1.6 JDK无法推断出正确的类型.以下似乎适用于我的机器:

                  It seems that Sun's 1.6 JDK can't infer the correct type. The following seems to work on my machine:

                  Set<Object> setOfObjects = Main.<Object, Integer>covariantSet(setOfInts);
                  

                  请注意,您必须调用静态方法以类名为前缀

                  Note that you must invoke the static method prefixed with the class name

                  这篇关于Java 泛型在 Eclipse 中编译,但在 javac 中不编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

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

                    <bdo id='JFCyY'></bdo><ul id='JFCyY'></ul>

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

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