Skip to content

Instantly share code, notes, and snippets.

@jnizet
Created April 16, 2019 20:00
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 jnizet/9f882dc1c462b616a34211f3b3a62273 to your computer and use it in GitHub Desktop.
Save jnizet/9f882dc1c462b616a34211f3b3a62273 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class InterfaceTest {
interface TestInterface {
default Set<String> getRequiredStrings() {
return Collections.emptySet();
}
}
static class B implements TestInterface {}
static class C extends B {}
static class D extends C {
@Override
public Set<String> getRequiredStrings() {
return new HashSet<>(Arrays.asList("Not an empty set"));
}
}
public static void main(String[] args) {
TestInterface d = new D();
System.out.println("d.getRequiredStrings() = " + d.getRequiredStrings());
}
}
@revanurupavan
Copy link

`public class InterfaceTest {

interface TestInterface {
    default Set<String> getRequiredStrings() {
        return Collections.emptySet();
    }
}

public abstract class B implements TestInterface { // few method implementations and abstract methods}
public abstract class C extends B {//few method implementations}

public class D extends C {
    @Override
    public Set<String> getRequiredStrings() {
        return new HashSet<>(Arrays.asList("Not an empty set"));
    }
}

public static void main(String[] args) {
    TestInterface d = new D();
    System.out.println("d.getRequiredStrings() = " + d.getRequiredStrings());
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment