Skip to content

Instantly share code, notes, and snippets.

@XavierCooney
Created July 12, 2023 12:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XavierCooney/e9f6235f05479ac6bf962ca25e31d8d0 to your computer and use it in GitHub Desktop.
Save XavierCooney/e9f6235f05479ac6bf962ca25e31d8d0 to your computer and use it in GitHub Desktop.
// 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