I have a method that procudes an Optional
But this String must be parsed at another application level as Integer or Long.
This I h
Using Optional.transform
just doesn't seem compatible with a transformation that might fail - theoretically this implies an optional optional, when what you want to do is consolidate absences. I would recommend using something like the following:
Optional strOptional = Optional.of("Toto");
Optional intOptional =
strOptional.isPresent()
? Optional.fromNullable(Ints.tryParse(strOptional.get()))
: Optional.absent();