Skip to content

Latest commit

 

History

History
executable file
·
11 lines (6 loc) · 903 Bytes

b33f.md

File metadata and controls

executable file
·
11 lines (6 loc) · 903 Bytes

Back to questions

Solution to b33f: Logging using a functional interface

See code at solutions/code/tutorialquestions/questionb33f

Compare the sample source code for this question with your solution.

Notice the use of the ifPresent method of Optional in my implementation of FileInspector. This takes a consumer -- a void function whose argument is the element type of the optional, and can be used to perform an operation on the element of the optional if it exists.

Notice also the use of the @FunctionalInterface annotation on the Logger and StringInspector interfaces. This annotation makes it illegal to add any more non-static, non-default methods to these interfaces, ensuring that it will always be possible to implement the interfaces concisely using lambdas. Think about why adding static or default methods is OK.