Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package aoc;
public class FuncRecursion {
static interface Func {
int apply();
}
static class ReturnZero implements Func {
@Override
public int apply() {
return 0;
}
}
static class AddOne implements Func {
private Func src;
public AddOne(Func src) {
super();
this.src = src;
}
@Override
public int apply() {
return src.apply()+1;
}
}
public static void main(String[] args) {
Func x = new ReturnZero();
for (int i = 0; i < 10; i++) {
x = new AddOne(x);
}
System.out.println(x.apply());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment