Let's say for example that I have
//...
String foo = "foo";
Boolean isFoo = (String input) -> input == foo;
//...
This lambda references a non-static outer-scope variable, therefore leading to JIT compilation never caching the lambda resulting in slower execution and more churn.
My current solution has been to do:
Boolean isFoo = ((String foo)-> (String input) -> input == foo).apply(foo);
This works for reference types and will snapshot value types. But if the variable is ever reassigned - this will fall short.
Is there a better way to do this?