import java.util.function.Function;

public class Main {
    public static void main(String[] args) {
        onestep(num -> {
            Magic<?> m = num > 0 ? new IntMagic() : new StrMagic();
            return m;
        });
    }

    static <T> T onestep(Function<Integer, Magic<T>> m) {
        return m.apply(1).step(m.apply(0).init());
    }
}

interface Magic<S> {
    S init();
    S step(S s);
}

class IntMagic implements Magic<Integer> {
    public Integer init() { return 0; }
    public Integer step(Integer s) { return s + 1; }
}

class StrMagic implements Magic<String> {
    public String init() { return ""; }
    public String step(String s) { return s + "0"; }
} 