简体   繁体   中英

Override Method in Builder

Example class:

public class Example {

    public boolean exampleMethod() {
        return false;
    }

}

So, now I wanted to add a Builder class (of course I have more things in my Example class). In there, I'd like to override the exampleMethod() method.

So I would like to do something like this:

ExampleBuilder builder = new ExampleBuilder();
//override method

Builder:

public class ExampleBuilder {

    //somehow override the exampleMethod with
    //given arguments (I could do it with
    //ExampleBuilder extends Example
    //but I don't think that is right)

}

Thanks for your answers in advance!

You can Override a declaration of method from interface, so instead you can use :

interface Example {
    public boolean exampleMethod();
}

class ExampleBuilder implements Example{

    @Override
    public boolean exampleMethod() {
      ///
    }
}

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