What is wrong with the code? Is Java 8 code acceptable here?