[slf4j-dev] [JIRA] (SLF4J-485) LoggingEventBuilder addArgument() should take Supplier, not Supplier

Sun, 01 Mar 2020 13:14:11 -0800

Christoffer Hammarström created SLF4J-485:
---------------------------------------------

             Summary: LoggingEventBuilder addArgument() should take 
Supplier<?>, not Supplier<Object>
                 Key: SLF4J-485
                 URL: https://jira.qos.ch/browse/SLF4J-485
             Project: SLF4J
          Issue Type: Bug
          Components: Core API
    Affects Versions: 2.0.0-alpha1
            Reporter: Christoffer Hammarström
            Assignee: SLF4J developers list


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

Try the following JUnit 4 test:


{noformat}
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());
    }
}
{noformat}



--
This message was sent by Atlassian JIRA
(v7.3.1#73012)
_______________________________________________
slf4j-dev mailing list
slf4j-dev@qos.ch
http://mailman.qos.ch/mailman/listinfo/slf4j-dev

Reply via email to