[英]Resolving hidden Type Parameter in Java
考慮以下代碼:
class Scratch<T> {
class InnerClass<T> {
public void executeHiddenMethod(){
//..some code to use Inner (T) type
T r = null; //declared T from inner T type
//..some code to use Outer (T) type
//?? How to use outer T type?
}
}
//when trying to invoke the code:
public static void main(String[] args) {
Scratch<String> scr = new Scratch<>();
Scratch<String>.InnerClass<Double> d = scr.new InnerClass<>();
d.executeHiddenMethod();
}
}
Scratch
的隱藏類型參數揭示到內部InnerClass
?除非我誤解了這個問題,否則您應該能夠為外部和內部 class 使用不同的類型參數T
代表Scratch
, S
代表InnerClass
。
class Scratch<T> {
class InnerClass<S> {
public void executeHiddenMethod(){
...
S s = null;
...
T t = null;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.