Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Created August 10, 2012 13:37
Show Gist options
  • Select an option

  • Save buzztaiki/3314255 to your computer and use it in GitHub Desktop.

Select an option

Save buzztaiki/3314255 to your computer and use it in GitHub Desktop.
内側の無名クラスから外側の無名クラスを見る
import java.util.Comparator;
public class A {
public static void main(String[] args) throws Exception {
new Comparator<String>() {
public int compare(String a, String b) {
new Runnable() {
public void run() {
try {
Comparator cmp = (Comparator)this.getClass().getDeclaredField("this$0").get(this);
System.out.println(cmp.toString());
} catch (Exception e) {}
}
}.run();
return a.compareTo(b);
}
}.compare("a", "b");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment