令牌“包”上的语法错误,预期导入(Java)(Syntax error on token “package”, import expected (Java))

编程入门 行业动态 更新时间:2024-10-28 21:18:50
令牌“包”上的语法错误,预期导入(Java)(Syntax error on token “package”, import expected (Java))

我想尝试在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.

更多推荐

本文发布于:2023-08-03 15:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395042.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   语法错误   Syntax   Java   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!