import java.util.function.Function; class Main { public static void main(String[] args) { Test test = new Test(); ((Function)(args.length == 2 ? (test::foo) : test::bar)).apply(""); } static class Test { public long foo(String s) { return 0; } public long bar(String s) { return 0; } } }