Optional

Best Practices for Java8 Optional

As we all know, Java 8 has a new class - Optional, which is mainly used to solve the common NullPointerException problem in the program. But in the actual development process many people are using Optional in a half-assed way, something like if (userOpt.isPresent()){...} Such code is everywhere. I would prefer to see an honest null judgment, but forcing Optional adds complexity to the code. The article I’m sharing with you today is some of the Best Practise and some of the Bad Practice of Java Optional, for your reference.