gpt4 book ai didi

java - 错误 : Class is not abstract and does not override abstract method

转载 作者:行者123 更新时间:2023-11-29 06:28:35 29 4
gpt4 key购买 nike

好吧,我正在尝试为 Bukkit/Spigot 编译一个 java 插件,但我收到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project Websend: Compilation failure
[ERROR] /home/bruno/spigot/Websend/src/main/java/com/github/websend/WebsendPlayerCommandSender.java:[24,7] error: WebsendPlayerCommandSender is not abstract and does not override abstract method sendTitle(String,String,int,int,int) in Player

错误所在的文件的各个部分(我的意思是):

public class WebsendPlayerCommandSender implements Player {
/* This class allows tapping into command output from plugins
* if the output is sent through the commandsender.
* Note to anyone having compilation problems: Compile against Bukkit, not CraftBukkit.
*
* Tap this method(1.6.4): sendRawMessage, sendMessage(String), sendMessage(String[])
*/

private final Player baseObject;
private final Plugin commandTargetPlugin;

public WebsendPlayerCommandSender(Player baseObject, Plugin commandTargetPlugin) {
this.baseObject = baseObject;
this.commandTargetPlugin = commandTargetPlugin;
}

@Override
public void sendMessage(java.lang.String param0) {
PluginOutputManager.handleLogRecord(commandTargetPlugin, new LogRecord(Level.INFO, param0));
baseObject.sendMessage(param0);
}

@Override
public void sendMessage(java.lang.String[] param0) {
for (String str : param0) {
PluginOutputManager.handleLogRecord(commandTargetPlugin, new LogRecord(Level.INFO, str));
}
baseObject.sendMessage(param0);
}

@Override
public void sendRawMessage(java.lang.String param0) {
PluginOutputManager.handleLogRecord(commandTargetPlugin, new LogRecord(Level.INFO, param0));
baseObject.sendRawMessage(param0);
}

还有这个:

public void sendTitle(String string, String string1) {
baseObject.sendTitle(string, string1);
}

插件不是我的,但我需要使用正确版本的 spigot 进行编译。问题是我不太了解java来解决这个错误。谁能帮帮我?

最佳答案

如果您想理解这个概念,请阅读整个答案,否则请阅读末尾并阅读解决方案的 block 引用。

Java中的接口(interface)顾名思义就是接口(interface)。如果我们专门从java的角度来看。接口(interface)是具有已声明但未实现的功能的类。因此,当其他一些类实现该接口(interface)时,该类必须实现接口(interface)的所有功能以及它自己的功能。

例如

这是java中的一个接口(interface)

public interface Animal {
public void eat();
public void travel();
}

这是一个实现它的类

public class MammalInt implements Animal {
@Override
public void eat() {
System.out.println("Mammal eats");
}

@Override
public void travel() {
System.out.println("Mammal travels");
}

public int noOfLegs() {
return 0;
}
}

当类实现接口(interface)时,您应该记住的唯一规则是它必须实现接口(interface)中声明的所有函数。

In your code you have already implemented sendMessage and sendRawMessage. Now to remove the error you only have to implement 'sendTitle' as shown in the error.

关于java - 错误 : Class is not abstract and does not override abstract method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44706656/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com