Question

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?

Was it helpful?

Solution

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

UnMarshaller<T> unmarshaller = new UnMarshaller<T>(schema, i);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top