All your T
different, but you can only see this if you call your methods using the full syntax :
For example, this code is valid:
new <Float>Rule<Integer>().<Character>Foo();
To simplify the explanation, suppose your code is:
class Rule<A> { public <B>Rule() { } public <C> void Foo() { } }
You can then explicitly declare generic types such as:
new <B>Rule<A>().<C>Foo();
If the types have the same name, the innermost one will be selected ( T
for the method, not the class):
Using this code using parameters:
class Rule<T> { public <T>Rule(T t) { } public <T> void Foo(T t) { } }
Then this is true:
new <Float>Rule<Integer>(3.2f);
Note that T
in the Float
constructor, not Integer
.
Another example:
class Example<T> { public <T> void foo1() {
I found another question related to method calls with explicit generic types without anything in front of them . It seems that static imports and method calls of the same class are the same. It seems that Java for some reason does not start the line with <Type>
.
source share