overriding methods without subclassing in Java

前端 未结 5 1924
时光取名叫无心
时光取名叫无心 2021-01-02 05:41

I started on a new project recently and saw the usage of overriding like below for the first time.

public class SomeClass {
  public void myMethod() {
    XS         


        
相关标签:
5条回答
  • 2021-01-02 06:08

    The new implementation for

    wrapMapper(MapperWrapper next)

    method is limited for this instance xstream

    XStream xstream

    this type of overriding is creating a class that extends XStream, that's why it is called Anonymous, do not have a name and you can not have a reference for it.

    0 讨论(0)
  • 2021-01-02 06:08

    Search Google for Anonymous Inner Class in Java

    That's pretty useful to implement interfaces or abstract Class methods on concrete objects

    That's heavily used when working with threading (Runnable class)

    0 讨论(0)
  • 2021-01-02 06:10

    That's an Anonymous Inner Class.

    0 讨论(0)
  • 2021-01-02 06:15

    That is called an "Anonymous class". You can find a lot of documentation about this special syntax on Internet. Good luck.

    0 讨论(0)
  • 2021-01-02 06:18

    In this case the XStream class is an anonymous inner class. Then you're overriding the method of your anonymous XStream class.

    0 讨论(0)
提交回复
热议问题