Вопрос по java, generics – Обобщения Java и Shadowing параметров типа

6

Error: User Rate Limit Exceeded

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?

Error: User Rate Limit Exceeded

Rule<String> r = new Rule<String>();

Error: User Rate Limit Exceededdo not conflict?Error: User Rate Limit Exceededdo conflictError: User Rate Limit Exceeded

SEE DISCUSSION BELOW

Error: User Rate Limit Exceeded

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.

Ваш Ответ

2   ответа
1

Error: User Rate Limit Exceeded<T>Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

public <P> Rule(P arg1, P arg2) {    
}

Error: User Rate Limit Exceeded<P>Error: User Rate Limit ExceededPError: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit Exceeded.

Also when you create an object does it use the type parameter of the class?

Error: User Rate Limit Exceeded

7

T:

new <Float>Rule<Integer>().<Character>Foo();

class Rule<A>
{

    public <B>Rule()
    {

    }
    public <C> void Foo()
    {

    }
 }

new <B>Rule<A>().<C>Foo();

T

class Rule<T>
{

    public <T>Rule(T t)
    {

    }
    public <T> void Foo(T t)
    {

    }
}

new <Float>Rule<Integer>(3.2f); 

TFloatInteger.

class Example<T> {

    public <T> void foo1() {
        // T here is the <T> declared on foo1
    }

    public void foo2() {
        // T here is the <T> declared on the class Example
    }
}

<Type>

Error: User Rate Limit Exceeded rubixibuc
Error: User Rate Limit Exceededx = <GenericType>callFunction()Error: User Rate Limit Exceedednew ArrayList<String>()Error: User Rate Limit Exceedednew <GenericTypeForConstructor>MyClass<GenericTypeForClass>()).
Error: User Rate Limit Exceeded rubixibuc
Error: User Rate Limit ExceededTError: User Rate Limit ExceededFooError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded rubixibuc

Похожие вопросы