Post History
Abuse anonymous classes Warning: This only works in very specific circumstances, and I've never actually needed it. Instead of defining a method outside of your method, you can make an instance o...
Answer
#1: Initial revision
# Abuse anonymous classes Warning: This only works in very specific circumstances, and I've never actually needed it. Instead of defining a method outside of your method, you can make an instance of an anonymous class to act as a closure. This'll only really help if what the method is closing over has a very long type or name. Here's an extremely contrived example where an extra method is defined because recursion is needed. ```java int g(List<Integer>b){return new Object(){int f(int x){return x>b.get(0)?f(x-1)*2:1;}}.f(3);} ``` The one above is 93 bytes, the one below is 97. ``` int g(List<Integer>b){return f(b,3);}int f(List<Integer>b,int x){return x>b.get(0)?f(b,x-1)*2:1;} ```