PrepZone Logo
PrepZone
Back to Java

Java · Medium

What are the best practices when using Optional in APIs?

JavaJava 8+

Answer preview

Use as return type, not as field or parameter. — Optional was designed for method return types. Avoid using it as a class field (not Serializable) or method parameter.…