为什么我们不需要导入java.lang包以在Java中使用Integer类(包装类) [英] Why We Don't Need To Import the java.lang package to use the Integer Class(Wrapper Classes) In Java

查看:1437
本文介绍了为什么我们不需要导入java.lang包以在Java中使用Integer类(包装类)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想创建 Integer (非int)类的对象,因为Integer类在另一个包中,我应该导入java.lang包来创建对象整数类。但我没有导入包,但编译器没有给我一个错误。

Suppose i want to make the object of an Integer(not int) Class,Since the Integer Class is in another package, i should have to import the java.lang package for creating the object of the Integer Class.But I didn't import the package ,yet compiler doesn't give me an error.

推荐答案

这是在 Java语言规范(JLS)第7章


编译单元[...]自动导入预定义包中声明的所有 public 类型 java.lang

这篇关于为什么我们不需要导入java.lang包以在Java中使用Integer类(包装类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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