Reputation: 525
Consider the following code:
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
into the inner class InnerClass
?Upvotes: 1
Views: 78
Reputation: 611
Unless I misunderstood the question, you should be able to use a different type parameter for the outer and inner class. T
for Scratch
and S
for InnerClass
.
class Scratch<T> {
class InnerClass<S> {
public void executeHiddenMethod(){
...
S s = null;
...
T t = null;
}
}
}
Upvotes: 1