Created
October 25, 2020 04:50
-
-
Save RayStarkMC/57b143a1bc86b2e35ba4309e64c9ec22 to your computer and use it in GitHub Desktop.
ジェネリッククラスでstaticメソッドの参照に失敗する問題の最小コード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.Consumer; | |
public class MethodResolveIssueSample { | |
static class NonGenericClass { | |
static <T> void f() { | |
h(NonGenericClass::<T>methodToBeReferenced); | |
} | |
static <T> void methodToBeReferenced(T t1) {} | |
} | |
static class GenericClass<Unused> { | |
static <T> void f() { | |
h(GenericClass::<T>methodToBeReferenced); // Cannot resolve method. | |
} | |
static <T> void methodToBeReferenced(T t1) {} | |
} | |
static <T> void h(Consumer<T> consumer) {} | |
} |
hメソッドの呼び出し時点で
MethodResolveIssueSample.<T>h(...);
とした場合はコンパイルに通る様子
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IDEAでのみNonGenericClass版の方のコンパイルが通っているように見える様子
実行しようとすると両方ともコンパイルエラーで弾かれる
IDEAのバグの可能性が高い