I have a simple question regarding java generics. How do I construct a generic class?
I have this class :
public class SearchResult<T extends Model> {
public List<T> results ;
public Integer count ;
public SearchResult(List<T> results, Integer count){
this.results = results;
this.count = count ;
}
}
Now i would like to create a new instance is SearchResult but then when i do this i get an error . SearchResult result = new SearchResult<MyModel>(myListOfMyModels, mycount);
Your class definition should look like
Then:
I’m assuming that since
myListOfStringsappears to be a string, you need to defineTas aString