Skip to content

Instantly share code, notes, and snippets.

@jonjack
Created November 14, 2018 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonjack/bf3045158541895823da3b198f468636 to your computer and use it in GitHub Desktop.
Save jonjack/bf3045158541895823da3b198f468636 to your computer and use it in GitHub Desktop.

Scenario: We have an interface that defines an operation.

public interface Validator {
  Optional validate(String subject, String subject2);
}

Some Validators only have 1 String to validate so we can extend the interface with a simpler one.

public interface SimpleValidator extends Validator {
  
  Optional validate(String subject);
  
  @Override
  default Optional validate(String subject, String subject2) {
    return validate(subject);
  }
}

The above can then be implemented as.

public class SomeSimpleValidator implements SimpleValidator {

  @Override
  public Optional validate(String subject) {
    ...
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment