Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

NilToObjE type inference breaks with lambdas #2

Copy link
Copy link

Description

@mintern
Issue body actions

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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.