You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SearchScope is currently defined as an enum which makes it impossible to use generics. We could convert it to class with static members to be able to use the same syntax and profit from generics.
// with this definition the above usage of globalSearch compiles:public <T> Pager<T> globalSearch(SearchScope<T> scope, Stringsearch, intitemsPerPage) {
// ...switch (scope) {
caseBLOBS:
return (newPager<>(this, scope.getResultType(), itemsPerPage, formData.asMap(), "search"));
// ...
}
}
publicstaticclassSearchScope<T> {
privateSearchScope(Class<T> resultType, StringjsonName) {
}
publicstaticfinalSearchScope<Project> PROJECTS = newSearchScope<>(Project.class, "projects");
publicstaticfinalSearchScope<SearchBlob> BLOBS = newSearchScope<>(SearchBlob.class, "blobs");
// JsonCreator, JsonValue and ToString can be implemented using the `jsonName` field
}
This would be a breaking change because code will have to be recompiled, although there should be no changes necessary on the users side.
The text was updated successfully, but these errors were encountered:
globalSearch currently returns a wildcard which always requires a cast afterwards, even though the return type is known for each SearchScope.
Ideally we would have a generic return type, based on SearchScope:
SearchScope is currently defined as an enum which makes it impossible to use generics. We could convert it to class with static members to be able to use the same syntax and profit from generics.
This would be a breaking change because code will have to be recompiled, although there should be no changes necessary on the users side.
The text was updated successfully, but these errors were encountered: