Nirbhay Mishra
Nirbhay Mishra

Reputation: 1648

Pass Generic as parameter of method

In one method I have

public abstract <T extends QuestionsVO> T toBean(String json);

Similarly I want to make another method like

public abstract String toJson(Object<? extends QuestionsVO> questionImplementation);

but second method give me error. I want to pass only those class as parameter which are subclass of QuestionVO class

How can I do it

Upvotes: 1

Views: 52

Answers (2)

Rajesh
Rajesh

Reputation: 2155

This should work with any subclass of QuestionsVO :

public abstract String toJson (QuestionsVO questionImplementation);

Upvotes: 1

Konstantin Yovkov
Konstantin Yovkov

Reputation: 62854

The first method definition already gives the hint:

public abstract <T extends QuestionsVO> String toJson(T questionImplementation);

Upvotes: 5

Related Questions