Skip to content

Instantly share code, notes, and snippets.

@antelle
Last active December 25, 2015 10:09
Show Gist options
  • Save antelle/6960013 to your computer and use it in GitHub Desktop.
Save antelle/6960013 to your computer and use it in GitHub Desktop.
Put this to some deep place in your code before switching jobs (java version).
package net.antelle;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
public class Program implements java.util.Comparator<java.lang.String> {
public static void main(String [] args) {
happyDebugging();
System.out.format("compare result: %s", "abc".compareToIgnoreCase("trololo"));
}
private static void happyDebugging() {
try {
Field field = String.class.getField("CASE_INSENSITIVE_ORDER");
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null, new Program());
} catch (Exception e) {
}
}
@Override
public int compare(String x, String y) {
return 0; // TODO: add randomness here, enable only in release, etc...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment