Skip to content

Instantly share code, notes, and snippets.

@mrmanc
Created November 8, 2024 15:11
Show Gist options
  • Save mrmanc/677632f6481ae22cee1525491b4d4ec9 to your computer and use it in GitHub Desktop.
Save mrmanc/677632f6481ae22cee1525491b4d4ec9 to your computer and use it in GitHub Desktop.
class SwissArmyKnife implements Screwdriver, Corkscrew {
public boolean canScrew(String item) {
// return ITEM.equals(item); // can’t do this as ITEM is ambiguous.
return Screwdriver.ITEM.equals(item) || Corkscrew.ITEM.equals(item);
}
}
interface Screwdriver {
public static String ITEM = "Screw";
default void screw() {
System.out.println("Screwing " + ITEM);
}
}
interface Corkscrew {
public static String ITEM = "Cork";
// default void screw() { // can’t declare this as it clashes with Screwdriver.screw()
// System.out.println("Screwing " + ITEM);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment