错误:类不是抽象的,不会覆盖抽象方法 [英] error: Class is not abstract and does not override abstract method

查看:116
本文介绍了错误:类不是抽象的,不会覆盖抽象方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Well, I'm trying to compile a java plugin for Bukkit/Spigot, but I'm getting the following error:

[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

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

The respective parts of the file where's the error (I mean):

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来解决这个错误.有人可以帮我吗?

The plugin ins't mine, but I need to compile with the correct version of spigot. The problem is that I don't know much about java to solve this error. Can anyone help me?

推荐答案

如果您想了解这个概念,请阅读整个答案,否则请阅读最后并阅读解决方案的块引用.

Java 中的接口顾名思义就是一个接口.如果我们专门从 Java 的角度来看.接口是具有声明但未实现的函数的类.因此,当其他某个类实现该接口时,该类必须同时实现接口的所有功能以及自己的功能.

An interface in java as its name suggests is just an interface. If we go specifically in java's perspective. Interface are classes with functions declared but not implemented. So when some other class implements that interface that class has to implement all the functions of interface also along with its own functions.

例如

这是java中的一个接口

This is an interface in java

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;
   }
}

当一个类实现一个接口时,你应该记住的唯一规则是它必须实现接口中声明的所有函数.

The only rule you should remember when a class implement an interface it has to implement all of the declared functions in interface.

在您的代码中,您已经实现了 sendMessagesendRawMessage.现在要消除错误,您只需实现错误中所示的sendTitle"即可.

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.

这篇关于错误:类不是抽象的,不会覆盖抽象方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆