Last active
April 10, 2023 10:08
-
-
Save kabutz/7ccb11a7f09392af33aa5843c8e007b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** In memory of @crazybob, who loved puzzles like this. */ | |
public class OverridingFinalToStringPuzzle { | |
private static class Bull { | |
public final String toString() { | |
return "Bull"; | |
} | |
} | |
public static String convert(Bull bull) { | |
return "%s".formatted(bull); | |
} | |
// Don't change anything above this line | |
public static void main(String... args) { | |
// TODO: Change this method so that the converted String becomes "Bear" | |
// without any command line flags (thus no deep reflection on String) | |
String result = convert(new Bull()); | |
if (!result.equals("Bear")) | |
throw new AssertionError("Should be \"Bear\""); | |
System.out.println("All good!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment