Skip to content

Instantly share code, notes, and snippets.

@msx80
Created March 1, 2021 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msx80/dfc5878f4595307a25807ca59292fd5c to your computer and use it in GitHub Desktop.
Save msx80/dfc5878f4595307a25807ca59292fd5c to your computer and use it in GitHub Desktop.
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