English 中文(简体)
为什么在ec片中而不是在 j木中自动打箱?
原标题:Why does automatic boxing work in eclipse but not in javac?
  • 时间:2011-10-27 15:14:41
  •  标签:
  • java
  • eclipse

该法典:

Integer ints[] = new Integer[]{ 1 ,  2 ,  3 };

只将胶卷中的罚款汇编成册,但javac(两种版本1.6.0_27和1.7.0)有以下错误:

BoxTest.java:4: incompatible types
found   : char
required: java.lang.Integer
               Integer ints[] = new Integer[]{ 1 ,  2 ,  3 };

BoxTest.java:4: incompatible types

为什么?

我假定它有某种编造旗,但挖掘出的粗金刚.并非直截了当。

最佳回答

javac不是这样做的,而是自动投放。 在<代码>javac上,该编码汇编如下:

Integer ints[] = new Integer[] { (int)  1 , (int)  2 , (int)  3  };

只有一个<代码>Integer,另一个在javac上,I ve在进行以下明确编辑:

Integer a = (int)  1 ;

但这里我发现的情况。 利用.Eclipse JDT batch codificationer ,从指挥线上运行,即使没有 cast:

$ java -jar org.eclipse.jdt.core_3.7.1.v_B76_R37x.jar -classpath rt.jar 
  -1.6 Appo.java 

I ve look at the javac,我认为没有任何办法改变这种行为。

我现在想推断,差异是由这一事实造成的。 内部没有使用<代码>javac,但联合执行监督委员会汇编者<>。

问题回答

Window -> Preference -> Compiler -> Errors/Warning -> Potential programming problems -> Boxing and unboxing conversions; set the value to Error

表面上看,来源的国旗被排在 Java的汽车前盒式上? 例如

javac - 来源1.4





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...