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?

MemLeak
  • 4,456
  • 4
  • 45
  • 84

1 Answers1

3

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

UnMarshaller<T> unmarshaller = new UnMarshaller<T>(schema, i);
rgettman
  • 176,041
  • 30
  • 275
  • 357
  • Its working. So the schema is useless? I'm able to do the method call like instantiateSomething(new Input()); ? – MemLeak Oct 15 '13 at 22:23
  • 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. – rgettman Oct 15 '13 at 22:25