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

inferred type does not conform to upper bound(s) when collecting Guava table

    XMLWordPrintable

    Details

    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      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


        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: