Whenever I need to define local helper methods in a class, I find myself wondering how exactly I should define them. The following three options seem interchangeable to me. Which one is best (objectively) and why? **I found several threads about static vs instance methods, but none which also mentioned local lambda's:
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();};