-1

Assuming that you have a lot of classes that extends the class Base.

class Base{}

class A extends Base[}

class B extends Base{}

class C extends Base{}

What must I write so that when I write a get method, I will get the class that I want?

public Base get(Class <? extends Base> clazz, final String key){
    //not important.
}

I want the method to return Objects of class A, B, or C, depending on the input clazz.

theAnonymous
  • 1,687
  • 2
  • 24
  • 59

1 Answers1

2
public <T extends Base> T get(Class<T> clazz, final String key) {
}

is closer to what you need. Keep in mind that during method declared generic variables, to have more success you typically put the modifiers outside of the parameter list.

Edwin Buck
  • 67,527
  • 7
  • 97
  • 130