Skip to content

NilToObjE type inference breaks with lambdas #2

@mintern

Description

@mintern

I can reproduce this minimally as follows:

import java.util.concurrent.Callable;

public class ExceptionInference {

    public static void main(String[] args) {
        String s = testInference(new NilToObjE<String, RuntimeException>() {
            @Override
            public String call() {
                return "compiles";
            }
        });
        s = testInference(new NilToObjE<String, RuntimeException>() {
            @Override
            public String call() {
                throw new RuntimeException("compiles");
            }
        });
        s = testInference(() -> "doesn't compile");
        s = testInference(() -> {
            throw new RuntimeException("doesn't compile");
        });
    }

    static <R, E extends Exception> R testInference(NilToObjE<R, E> f) throws E {
        return f.call();
    }

    @FunctionalInterface
    interface NilToObjE<R, E extends Exception> extends Callable<R> {
        @Override
        R call() throws E;
    }
}

This seems to be either a bug or a limitation in Java, and it makes NilToObjE much less useful than it should be.

I'm planning to bump to 2.0 with a version that doesn't extend Callable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions