Akadisoft
Akadisoft

Reputation: 306

Return a List of type that is given as parameter to a method?

I want to create a method that will execute a query and return a Set of object of specific type. The type is given as param to method as follow:

Set<Person> people = Dao.executeQuery("select * from PERSON",Person.class);

In Dao class I would like to define the method as follow:

public static Set<???> executeQuery(String sql, ????){}

Can you please help me on how to write executeQuery method?

Upvotes: 2

Views: 90

Answers (2)

opi
opi

Reputation: 244

public static <T> Set<T> executeQuery( String sql, Class<T> type );

Upvotes: 2

faylon
faylon

Reputation: 7450

public static <T> Set<T> executeQuery(String sql, Class<T> klass) {

    return null;
}

Upvotes: 6

Related Questions