Autoboxing无法将int转换为Integer [英] Autoboxing can't convert an int to an Integer

查看:87
本文介绍了Autoboxing无法将int转换为Integer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个完全的初学者,我正在努力学习java。我读到了 Autoboxing 取消装箱 这里



我正在研究java版本1.8.0_05并使用Eclipse。



代码是:

  class Test {
public static void main(String [] args){
Integer iob = 100; //显示错误 - >类型不匹配:无法从int转换为整数
}
}

谢谢帮助。

解决方案

您需要将语言级别设置为至少1.5 / 5.0才能利用自动装箱/拆箱功能。



更改项目中的设置 - >属性 - > Java编译器,可能是,它没有设置到正确的级别。



注意这不是你所用的JDK版本的直接关联重新使用,它只是表示将java代码解释为不高于语言级别版本的级别,使用至少等于或高于给定语言级别设置的任何特定版本的JDK。 / p>

IE:您使用的是JDK 1.8+,将语言级别设置为5.0意味着您只能使用高达JDK 1.5的java功能。


I am a complete beginner and I'm trying to learn java. I read about the concept of Autoboxing and Unboxing here.

I am working on java version 1.8.0_05 and using Eclipse.

The code is :

class Test {
    public static void main(String[] args) {
        Integer iob = 100; // shows error -> Type mismatch: Cannot convert from int to Integer
    }
}

Thanks for the help.

解决方案

You need to have your language level set to at least 1.5/5.0 to take advantage of autoboxing/unboxing.

Change your settings in Project --> Properties --> Java Compiler, chances are, it's not set to the right level.

Note this is NOT directly tied to the version of the JDK you're using, it simply means the level in which your java code will be interpreted as if it were no higher than the language level version, using any particular version of the JDK that is at least at or higher than the given language level setting.

IE: you're using JDK 1.8+, setting your language level to 5.0 means you will only be able to use java features that are up to JDK 1.5.

这篇关于Autoboxing无法将int转换为Integer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆