Q:

Calling method from a generic wildcard reference

the following code is reduced to the essentials for the question:
public class GenericTest 
{
    private interface CopyInterface<T extends CopyInterface<T>>
    {
        public void copyFrom(T source);
    }

    public void testMethod()
    {
        CopyInterface<?> target;
        CopyInterface<?> source;
        target.copyFrom(source);
    }
}

This leads to the following compiler error message:
The method copyFrom(capture#1-of ?) in the type GenericTest.CopyInterface is not applicable for the arguments (GenericTest.CopyInterface)   GenericTest.java    /ACAF/src/de/tmasoft/acaftest/attributes    line 14 Java Problem
When I use the raw type for the variable target, I just get a raw-type warning. Is there a way to get this compiled without using a raw-type?

A:

You have to make your testMethod() generic and declare that source and target are of the same type:
public <T extends CopyInterface<T>> void testMethod() {
    T target = ...; //initialize the variable
    T source = ...; //initialize the variable
    target.copyFrom(source);
}

