Generics Java and Shadowing of type parameters
Posted
by
rubixibuc
on Stack Overflow
See other posts from Stack Overflow
or by rubixibuc
Published on 2012-04-14T04:43:43Z
Indexed on
2012/04/14
5:29 UTC
Read the original article
Hit count: 159
This code seems to work fine
class Rule<T>
{
public <T>Rule(T t)
{
}
public <T> void Foo(T t)
{
}
}
- Does the method type parameter shadow the class type parameter?
- Also when you create an object does it use the type parameter of the class?
example
Rule<String> r = new Rule<String>();
Does this normally apply to the type parameter of the class, in the situation where they do not conflict? I mean when only the class has a type parameter, not the constructor, or does this look for a type parameter in the constructor? If they do conflict how does this change?
SEE DISCUSSION BELOW
if I have a function call
x = <Type Parameter>method(); // this is a syntax error even inside the function or class ; I must place a this before it, why is this, and does everything still hold true. Why don't I need to prefix anything for the constructor call. Shouldn't Oracle fix this.
© Stack Overflow or respective owner