简体   繁体   中英

Why I can't override handleMessage method when I initialize a Handler object?

  • It should be like this :

     Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); } };
  • However,in my IDE,it must be overrided like this:

     Handler handler = new Handler() { @Override public void close() { } @Override public void flush() { } @Override public void publish(LogRecord logRecord) { } };

And it seems that the Handler object here doesn't support such method called "handleMessage".

What should I do?

That's a name conflict between different Handler classes.

The first Handler you mention seems to be a javax.xml.ws.handler.Handler docs or a android.os.Handlerdoc , both of which have a handleMessage method to override.

The second Handler seems like it is a java.util.logging.Handler docs that has the methods you mention

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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