Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-485

LoggingEventBuilder addArgument() should take Supplier<?>, not Supplier<Object>

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • 2.0.0-alpha2
    • 2.0.0-alpha1
    • Core API
    • None
    • major

    Description

      `addArgument(Supplier<Object>)` prevents passing in any `Supplier<? extends Object>`.

      Try the following JUnit 4 test:

      import java.util.function.Supplier;
      import org.junit.Test;
      
      public class GenericsTest {
      
          @Test
          public void testObjectSupplier() {
              Supplier<Object> objectSupplier = () -> "Object";
              Supplier<String> stringSupplier = () -> "String";
      
              object(objectSupplier);
              //object(stringSupplier); // Uncommenting leads to compile failure
      
              //string(objectSupplier); // Uncommenting leads to compile failure
              string(stringSupplier);
      
              extendsObject(objectSupplier); // Works fine
              extendsObject(stringSupplier); // Works fine
          }
      
          private void object(Supplier<Object> objectSupplier) {
              System.out.println("object: "+objectSupplier.get());
          }
      
          private void string(Supplier<String> stringSupplier) {
              System.out.println("string: "+stringSupplier.get());
          }
      
          private void extendsObject(Supplier<?> extendsObjectSupplier) {
              System.out.println("extends object: "+extendsObjectSupplier.get());
          }
      }
      

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            kreiger Christoffer Hammarström
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: