Hack Forums
[Java] Overriding method out of Library does not work - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Overriding method out of Library does not work (/showthread.php?tid=5599905)



Overriding method out of Library does not work - Zippy™ - Apr 14, 2017

GamersBot.java : https://pastebin.com/7HbGrzCd
Cefh.java : https://pastebin.com/MZeVDqkx
Screenshot: http://prnt.sc/ewm2dn

The output generated:
Code
xjoeyv.cefh.MessageTransporterEvent@4208289f
xjoeyv.cefh.MessageTransporterEvent@5e8d667f
Is a part of the 'library' and comes from the function:
Code
public void onMessageTransport(MessageTransporterEvent event) {
    System.out.println(event);
}
And my function on the left side does not override it, why not? The function in the Cefh.java file will get called as you can see.


* - Weco - Apr 14, 2017

You need to call GamersBot.onMessageTransport if you want to use the overridden function.


* - SIM-429621 - Apr 14, 2017

Where's the rest of the code ? How do you know that onMessageTransport() is not being overridden in GamersBot class, you used "@override" annotation so you imply to the compiler that you actually want to override a method in the code that follows, and if it doesn't give you an error than it means it actually is being overridden, the mistake may be in the part of code where you call these methods.


* - Zippy™ - Apr 15, 2017

(Apr 14, 2017 06:08 PM)Weco Wrote:  You need to call xjoeyv.gamersbot.Cefh.onMessageTransport if you want to use the overridden function.

You mean what happends here?
Code
package xjoeyv.cefh;

import org.cef.browser.CefBrowser;
import org.cef.callback.CefQueryCallback;
import org.cef.handler.CefMessageRouterHandlerAdapter;

public class MessageTransporter extends CefMessageRouterHandlerAdapter {
    
    @Override
    public boolean onQuery(CefBrowser browser,
            long query_id,
            String request,
            boolean persistent,
            CefQueryCallback callback) {    
        Cefh.getInstance().onMessageTransport(new MessageTransporterEvent(callback, request));
        return false;
    }
}

(Apr 14, 2017 06:47 PM)Passenger Wrote:  Where's the rest of the code ? How do you know that onMessageTransport() is not being overridden in GamersBot class, you used "@override" annotation so you imply to the compiler that you actually want to override a method in the code that follows, and if it doesn't give you an error than it means it actually is being overridden, the mistake may be in the part of code where you call these methods.

See above ^^
"How do you know that onMessageTransport() is not being overridden in GamersBot class" and how do you mean that? GamersBot class should override it right? Or that is what I want


* - Weco - Apr 15, 2017

(Apr 15, 2017 02:05 AM)Zippy™ Wrote:  You mean what happends here?
Code
package xjoeyv.cefh;

import org.cef.browser.CefBrowser;
import org.cef.callback.CefQueryCallback;
import org.cef.handler.CefMessageRouterHandlerAdapter;

public class MessageTransporter extends CefMessageRouterHandlerAdapter {
    
    @Override
    public boolean onQuery(CefBrowser browser,
            long query_id,
            String request,
            boolean persistent,
            CefQueryCallback callback) {    
        Cefh.getInstance().onMessageTransport(new MessageTransporterEvent(callback, request));
        return false;
    }
}

public boolean onQuery gets Overriden, so whenever MessageTransporter.onQuery is called, the overriden function will be used instead of the original.


* - Zippy™ - Apr 15, 2017

(Apr 15, 2017 06:28 AM)Weco Wrote:  public boolean onQuery gets Overriden, so whenever MessageTransporter.onQuery is called, the overriden function will be sued instead of the original.

So how can I resolve this issue? What should be the best way to go? Cause I do want the function to be overriden in the Cefh class.


* - Weco - Apr 15, 2017

(Apr 15, 2017 07:02 AM)Zippy™ Wrote:  So how can I resolve this issue? What should be the best way to go? Cause I do want the function to be overriden in the Cefh class.

You simply call GamersBot.onMessageTransport instead of Cefh.onMessageTransport :)
You can read more here: http://docs.oracle.com/javase/tutorial/java/IandI/override.html


* - Zippy™ - Apr 15, 2017

(Apr 15, 2017 08:35 AM)Weco Wrote:  You simply call GamersBot.onMessageTransport instead of Cefh.onMessageTransport :)
You can read more here: http://docs.oracle.com/javase/tutorial/java/IandI/override.html

Yea but I said the Cefh is a library so people can use it them selfs, this can end up that someone else its class is CefBrowser that wants to override the onMessageTransport.