-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method reference for constructor produces weird error with @UnderInitialization #3637
Comments
Thanks for the small test case. The essence of the error is:
This indicates a mismatch between
Here is a simplified version of your test case (with an import java.util.Objects;
public interface DirectedGraph<V> {
interface EdgeFactory<V> {
Object createEdge(V v0);
}
}
class DefaultEdge {
public final Object source;
public DefaultEdge(Object sourceArg) {
this.source = Objects.requireNonNull(sourceArg);
}
public static <V> DirectedGraph.EdgeFactory<V> factory() {
return DefaultEdge::new; // <-- error here
}
}
To make the code type-check, you can change the annotations to better express the contract: import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Objects;
public interface DirectedGraph<V> {
interface EdgeFactory<V> {
Object createEdge(V v0);
}
}
class DefaultEdge {
public final Object source;
public DefaultEdge(Object sourceArg) {
this.source = Objects.requireNonNull(sourceArg);
}
// added "extends @NonNull Object" on line below
public static <V extends @NonNull Object> DirectedGraph.EdgeFactory<V> factory() {
return DefaultEdge::new;
}
} I agree the error message is a bit hard to interpret. Let us know if you have a suggestion for clarifying it. |
It looks like I somehow fixed the error because the current code is indeed It might be a case of an unfortunate naming. The parameter name is What do you think of moving found/required before the full type signatures? |
This is a good idea. Thanks. I will open a pull request with that change. |
The text was updated successfully, but these errors were encountered: