Created
March 1, 2021 08:07
-
-
Save msx80/dfc5878f4595307a25807ca59292fd5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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