有谁能告诉我为什么不编译?
public class TestClass { private boolean doThis = false; protected void fooThat() {} protected void fooThis() {} public void execute() { (doThis ? this::fooThis : this::fooThat).run(); } }
解决方法
你想要的是什么
(doThis ? this::fooThis : (Runnable) (this::fooThat)).run();
Java不能从方法名称推断你期望的类型?:返回.
我不知道这比谁好
if (doThis) fooThis(); else fooThat();