当前位置: 代码迷 >> Java相关 >> 请问这个程序有错吗?
  详细解决方案

请问这个程序有错吗?

热度:137   发布时间:2007-01-10 13:14:20.0
请问这个程序有错吗?

public class hcx{
public static void main(String args[ ]){
Boolean b=new Boolean("TRUE");
if(b){
for(Integer i=0;i<10;i++){
System.out.println(i);
}
}
}
}
这个程序在我的机器上编译无法通过,而在别人的机上可以通过,请问各位这个程序有没错啊?

[此贴子已经被作者于2007-1-10 13:50:21编辑过]

搜索更多相关的解决方案: public  Boolean  args  机器  

----------------解决方案--------------------------------------------------------
我这儿能运行阿  也没有编译错误啊
----------------解决方案--------------------------------------------------------
你机子是什么牌子?
----------------解决方案--------------------------------------------------------
在我的机上编译就会出现以下的错误:
hcx.java:4: incompatible types
found : java.lang.Boolean
required: boolean
if(b){
^
hcx.java:5: incompatible types
found : int
required: java.lang.Integer
for(Integer i=0;i<10;i++){
^
hcx.java:5: operator < cannot be applied to java.lang.Integer,int
for(Integer i=0;i<10;i++){
^
hcx.java:5: operator ++ cannot be applied to java.lang.Integer
for(Integer i=0;i<10;i++){
----------------解决方案--------------------------------------------------------
JDK1.5以后才支持自动开箱动作

JDK1.5以前的不支持

楼主的电脑编译不了,是因为你用的JDK是老版本的

----------------解决方案--------------------------------------------------------

----------------解决方案--------------------------------------------------------
我使用也是JDK1.5.随便问一下,开箱动作是什么来的啊?

[此贴子已经被作者于2007-1-10 16:58:11编辑过]


----------------解决方案--------------------------------------------------------
是JVM自动帮你做的

也就是比如

Integer i1=new Integer(15);
int i2=10;

int s=i1+i2;

这个会成立,JVM自动帮你把i1变成int值
----------------解决方案--------------------------------------------------------
哦,谢谢各位了!
----------------解决方案--------------------------------------------------------
  相关解决方案