Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8232933

Javac inferred type does not conform to equality constraint

XMLWordPrintable

    • b23
    • x86_64
    • os_x

        A DESCRIPTION OF THE PROBLEM :
        In Java 11 when i try to compile code sometimes it compiles, sometimes it fails.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile couple times

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Success compilation
        ACTUAL -
        Error:(10, 58) java: incompatible types: inferred type does not conform to equality constraint(s)
            inferred: java.util.List<Main.A<?,?>>
            equality constraints(s): java.util.List<capture#1 of ? extends Main.A<?,?>>

        ---------- BEGIN SOURCE ----------
        import java.util.LinkedList;
        import java.util.List;
        import java.util.Map;
        import java.util.stream.Collectors;

        public class Main {

            public static void main(String[] args) {
                List<? extends A<?, ?>> a = new LinkedList<>();
                Map<String, List<A<?, ?>>> b = a.stream().collect(
                        Collectors.groupingBy(A::getval, Collectors.toList())
                );

                System.out.println("Hello World!");
            }

            class A<K, V> {
                String getval() {
                    return "sss";
                }
            }
        }
        ---------- END SOURCE ----------

        FREQUENCY : often


              vromero Vicente Arturo Romero Zaldivar
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Created:
                Updated:
                Resolved: