-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.

asked Jun 11, 2017 at 15:36
0

1 Answer 1

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.

answered Jun 11, 2017 at 15:40
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Tom, in my hurry I forgot to add it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.