Error: inferred type does not conform to lower bound(s) after java 11 upgrade

Viewed 648

After upgrading the project from java 8 to java 11 I randomly get the following error:

incompatible types: inferred type does not conform to lower bound(s)
[ERROR]     inferred: java.lang.String
[ERROR]     lower bound(s): java.lang.Object,java.lang.String

The piece of code I am getting it:

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Test {

    public static void main(String[] args) {
        List<String[]> list = Arrays.asList(new String[] {"a", "a", "a"}, new String[] {"b", "a", "b"});
        final Map<Integer, List<String[]>> dynamicFilesByPosition = Map.of(1, list);
        final Boolean result = dynamicFilesByPosition.values().stream()
                .map(strings -> {
                    final Map<String, Boolean> multipleDynamicTypesOnSamePosition = strings.stream()
                            .map((String[] value) -> value[0])
                            .collect(
                                    Collectors.groupingBy(
                                            Function.identity(),
                                            Collectors.collectingAndThen(Collectors.toSet(), set -> set.size() > 1)
                                    )
                            );
                    return multipleDynamicTypesOnSamePosition.size() > 1;
                })
                .filter(Boolean::booleanValue)
                .findAny()
                .orElse(false);
        System.out.println(result);
    }
}

With changes in the a, b letter I get the error. After a few errors it starts working.

I am using maven for the build:

$ mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.6.3
Java version: 11.0.7, vendor: AdoptOpenJDK, runtime: /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
Default locale: en_RO, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.3", arch: "x86_64", family: "mac"
0 Answers
Related