java 8 collect List<String>

1.1k Views Asked by At

I am collecting String in List using Java 8. But, this is giving me compile error that

incompatible types: inference variable T has incompatible bounds equality constraints: String lower bounds: Object

final List<ProjectLevel> levels = projectLevelFacade
                    .findUUIDByNameorNumber(freeText, businessAccountId);
final List<String> uuids = levels
                    .stream()
                    .map((level) -> level.getProjectLevelsUUIDs()) // this return List<String>
                    .flatMap(Collection::stream)
                    .collect(Collectors.toList());

can any one have idea how to achieve this using Java 8?

Is there any type of casting or something for this?

I have also taken reference from here.

1

There are 1 best solutions below

7
On BEST ANSWER

ProjectLevel is a generic class - when you write List<ProjectLevel> you are using a raw type and the type inference system does not work any longer.

Try:

final List<ProjectLevel<?>> levels = projectLevelFacade
                .findUUIDByNameorNumber(freeText, businessAccountId);

and it should compile as expected.