java - "Cannot subclass the final class"错误,但类不是最终的

标签 java inheritance package final-class

这是我的代码:

package basic;

public abstract class Entity {}

package characters;

import basic.Entity;

public abstract class Character extends Entity {}

package player;

public class Player extends Character {}

我收到了

The type Player cannot subclass the final class Character.

但我检查了一百万次,我还没有在我的项目中使用 final 一次。什么给了?

最佳答案

您正在扩展 java.lang.Character(不需要导入,因为它来自 java.lang)。

import characters.Character 插入到您的 Player 代码中。


引用:using package members :

For convenience, the Java compiler automatically imports two entire packages for each source file: (1) the java.lang package and (2) the current package (the package for the current file).

关于java - "Cannot subclass the final class"错误,但类不是最终的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53779769/

相关文章:

Python 2.7 如何在 "imp"导入的代码导入语句上欺骗 python

c - R包卸载的时候一定要卸载动态库吗?

java - 如何更改微调器的文本颜色

java - 谷歌 GSON : How to use @Since annotation for e. g。版本 "1.2.1"? (无效双)

java - 如何在eclipse中运行外部jar库

c# - 泛型的继承

java - 无法从 tomcat 中取消部署我的 webapp war 文件

scala - Scala 对象定义中没有父类(super class)名称的 "extends {..}"子句有什么作用?

java - 为什么叫它 "method hiding"?

java - 控制 Java 中的包依赖关系 (Eclipse)