StupidBeauty
Read times:1180Posted at:Mon Aug 15 01:17:18 2022 - no title specified

Java/使用保留关键字interface 作为标识符/导致错误/ 错误: 需要<标识符>

Java中的保留关键字都不能作为标识符使用,包括不能作为包名中的片断使用,否则编译时会遇到错误:

错误: 需要<标识符>

例如,以下代码文件,由于其包名路径中有一段是interface ,导致编译时出错。

package com.stupidbeauty.musicphone. interface ;

public interface MusicCallCallbackInterface {

}

编译时会这样出错:

bash-5.0# javac /HkLunch/SoftwareDevelop/musicphone/MusicPhone.earn/app/src/main/java/com/stupidbeauty/musicphone/interface/MusicCallCallbackInterface.java
/HkLunch/SoftwareDevelop/musicphone/MusicPhone.earn/app/src/main/java/com/stupidbeauty/musicphone/interface/MusicCallCallbackInterface.java:1:
错误 : 需要 < 标识符 >
package com.stupidbeauty.musicphone.
interface ;
                                   ^
1
个错误

解决方法就是,包名路径中不要使用关键字,将interface 改成 interfaces 。文件系统中的目录名字同步修改。

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands