0

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?

1 Answer 1

3

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

UnMarshaller<T> unmarshaller = new UnMarshaller<T>(schema, i);
Sign up to request clarification or add additional context in comments.

2 Comments

Its working. So the schema is useless? I'm able to do the method call like <SubClasOfA>instantiateSomething(new Input()); ?
It doesn't look like schema is useless, depending on its purpose. You pass it to the UnMarshaller constructor. If the only purpose of it is to define T, then it's not necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.