Always Take the Option
by in CodeSOD on 2026-08-04Frequent submitter Capybara James sends us this simple snippet, which highlights that even when you have the lovely convenience of Optional types, you can use them wrong.
if (StringUtils.hasLength(dto.getAssetModelUUID())
// Other conditions
) {
return Optional.ofNullable(dto);
}