Created
November 8, 2024 15:11
-
-
Save mrmanc/677632f6481ae22cee1525491b4d4ec9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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