我想尝试在Eclipse中导入Java中的java.lang.Math,并在标题中出现错误。 这是我的代码的开始:
import java.lang.Math; package test1;这个错误在“package test1;”下弹出
I am trying trying to import java.lang.Math in Java on Eclipse and am getting the error in the title. Here is the beginning of my code:
import java.lang.Math; package test1;This error is popping up under "package test1;"
最满意答案
package必须首先在文件中package声明,甚至包括导入:
package hw1; import java.lang.Math;另外,你不需要导入java.lang.Math或者java.lang任何东西。
JLS第7章说:
编译单元自动访问其包中声明的所有类型,并自动导入预定义包java.lang中声明的所有公共类型。
The package statement must be first in the file, before anything, even imports:
package hw1; import java.lang.Math;Plus, you don't need to import java.lang.Math, or anything in java.lang for that matter.
The JLS, Chapter 7 says:
A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang.
更多推荐
发布评论