문제

Following example is not the original code, I'm not looking for a workaround.

There is a Class For Generic Parsing/UnMarshalling like:

public class UnMarshaller<T extends AClass> {
...

This works fine, until I try to provide a Generic Method to access it.

public class UnMarshall{
...
// the T schema is every time a Subclass of AClass
public <T extends AClass> Queue<T> instantiateSomething(Input i, T schema) {
    UnMarshaller<schema> unmarshaller= new UnMarshaller<schema>(schema, i);
    return unmarshaller.getQueue();
}
...

UnMarshaller<schema> and new UnMarshaller<schema> are troubleing, but i doesn't get it. How can I instantiate this class?

도움이 되었습니까?

해결책

When using a generic type parameter, supply the class/type name, not the variable name:

UnMarshaller<T> unmarshaller = new UnMarshaller<T>(schema, i);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top