-
-
Save XavierCooney/e9f6235f05479ac6bf962ca25e31d8d0 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
// requires Java 19+ | |
class WatSequence implements CharSequence { | |
public CharSequence subSequence(int start, int end) { | |
return this; | |
} | |
public int length() { | |
return 2; | |
} | |
public char charAt(int index) { | |
// look Ma, no concurrency! | |
if (index == 1) throw new RuntimeException(); | |
return '⁉'; | |
} | |
public String toString() { | |
return "wat"; | |
} | |
} | |
class Wat { | |
static String wat() { | |
if (Runtime.version().feature() < 19) { | |
throw new RuntimeException("this doesn't work pre java-19 :("); | |
} | |
StringBuilder sb = new StringBuilder(); | |
try { | |
sb.append(new WatSequence()); | |
} catch (RuntimeException e) {} | |
return new String(sb); | |
} | |
public static void main(String[] args) { | |
String s = wat(); | |
System.out.println(s.isEmpty() && !s.equals("")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment