简体   繁体   English

方法不会在Java中从其超类重写方法

[英]Method does not override method from its superclass in java

I have the above title error message on my override methods. 我的重写方法上有上述标题错误消息。 I've followed this pubnub tutorial to try and get a working example and can't figure out why I'm getting these messages. 我已经遵循了该pubnub教程来尝试获取有效的示例,但无法弄清楚为什么收到这些消息。 The only difference is I'm using intellij. 唯一的区别是我正在使用intellij。 Here's the tutorial in case it helps. 如果有帮助,这里是本教程。

Here's my code: 这是我的代码:

import com.pubnub.api.*;
import com.sun.org.apache.xpath.internal.operations.String;

public class SubscribePublishExample {

    //Creating an instance of pubnub and adding the subscribe code.
    public void subscribePublish() {
        final Pubnub pubnub = new Pubnub("demo", "demo");

        try {
            pubnub.subscribe("Hell0 World", new Callback() {

                @Override
                public void successCallback(String arg0, Object arg1) {
                    System.out.println(arg1);
                }

                //Adding the publish code into the connect callback.
                @Override
                public void connectCallback(String arg0, Object arg1) {
                    pubnub.publish("Hello_World", "Hello World !", new Callback() {
                        @Override
                        public void successCallback(String arg0, Object arg1) {
                            System.out.println(arg1);
                        }
                    });


                }
            });
        } catch (PubnubException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new SubscribePublishExample().subscribePublish();
    }
}

I'm assuming Callback is an interface. 我假设Callback是一个接口。 Based on the first time you implement it (when you pass it to pubnub.subscribe() ) using an abstract class instance, it has two methods - successCallback() and connectCallback() . 基于您第一次使用抽象类实例实现它(将它传递给pubnub.subscribe() ),它具有两个方法successCallback()connectCallback()

However, inside your connectCallback() implementation, you have another abstract class instance implementing Callback (which you pass to pubnub.publish() ), and this time you forgot to implement connectCallback() . 但是,在connectCallback()实现内部,您有另一个实现Callback抽象类实例(将其传递给pubnub.publish() ),但是这次您忘记实现connectCallback()

    pubnub.subscribe("Hell0 World", new Callback()
    {

        @Override
        public void successCallback(String arg0, Object arg1)
        {
            System.out.println(arg1);
        }
        //Adding the publish code into the connect callback.
        @Override
        public void connectCallback(String arg0, Object arg1)
        {
            pubnub.publish("Hello_World", "Hello World !", new Callback()
            {
                @Override
                public void successCallback(String arg0, Object arg1)
                {
                    System.out.println(arg1);
                }

                // here you should add an implementation of connectCallback :
                @Override
                public void connectCallback(String arg0, Object arg1)
                {
                    // some code
                }
            });


        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM