1

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.

Community
  • 1
  • 1
Hiren
  • 1,427
  • 1
  • 18
  • 35

1 Answers1

4

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.

assylias
  • 321,522
  • 82
  • 660
  • 783