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

error at compile time:inferred type does not conform to upper bound(s) when collecting to a HashMap

XMLWordPrintable

    • Cause Known
    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      Attached code does not compile.
      I use Guava 27.0-jre.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      paste the code into any main method and try to compile it with javac

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      program compiles
      ACTUAL -
      incompatible types: inferred type does not conform to upper bound(s)
      inferred: com.google.common.collect.Table<java.lang.Object,java.lang.Object,java.lang.Object>
      upper bound(s): com.google.common.collect.Table<java.lang.Object,java.lang.Object,java.lang.Object>,com.google.common.collect.Table<? extends java.lang.Integer,? extends java.lang.Integer,? extends java.lang.Integer>,java.lang.Object

      ---------- BEGIN SOURCE ----------
      final Table<Integer, Integer, Integer> destination = HashBasedTable.create();
      final Map<Integer, Integer> source = new HashMap<>();

      // doesn't compile
      destination.putAll( source.entrySet().stream().collect( Tables.toTable( e -> 0, e -> 0, e -> 0, ( e1, e2 ) -> 0, HashBasedTable::create ) ) );
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      final Table<Integer, Integer, Integer> destination = HashBasedTable.create();
      final Map<Integer, Integer> source = new HashMap<>();

      // compiles
      final Table<Integer, Integer, Integer> broker = source.entrySet().stream().collect( Tables.toTable( e -> 0, e -> 0, e -> 0, ( e1, e2 ) -> 0, HashBasedTable::create ) );
      destination.putAll( broker );

      FREQUENCY : always


            dlsmith Dan Smith
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: