String id = instanceWithIdAsString.map(ClassWithIdAsString::getId)
.map(id -> String.valueOf(id))
.orElseGet(() -> instanceWithIdAsLong
.map(ClassWithIdAsLong::getId).orElse(""));
Doesn't ClassWithIdAsString :: getId return String as ID and ClassWithIdAsLong :: getId long as ID?
If so, it should be the other way around:
String id = instanceWithIdAsString.map(ClassWithIdAsLong::getId)
.map(id -> String.valueOf(id))
.orElseGet(() -> instanceWithIdAsLong
.map(ClassWithIdAsString::getId).orElse(""));
, null, "".
, .
, .