Lazy field initialization with lambdas
问题 I would like to implement lazy field initialization (or deferred initialization) without an if statement and taking advantage of lambdas. So, I would like to have the same behavior of the following Foo property but without the if : class A<T>{ private T fooField; public T getFoo(){ if( fooField == null ) fooField = expensiveInit(); return fooField; } } Ignore the fact that this solution is not guaranteeing safe use for: 1) multi-threading; 2) null as a valid value of T . So, to express the