每当我需要在类中定义本地帮助器方法时,我发现自己想知道我应该如何定义它们。以下三个选项似乎可以互换。哪一个最好(客观),为什么? **我找到了几个关于静态与实例方法的线程,但没有提到本地lambda的内容:
private void ifEmpty(Collection c) {
if(c.isEmpty())
throw new IllegalStateException();
}
private static void ifEmpty(Collection c) {
if(c.isEmpty())
throw new IllegalStateException();
}
private Consumer<Collection> ifEmpty = (c) -> {if(c.isEmpty()) throw new IllegalStateException();};