fork download
  1. import java.util.Date;
  2.  
  3. public class Main {
  4.  
  5. static class Comment { }
  6.  
  7. static class User { }
  8.  
  9. interface SortBy<T, M> { }
  10.  
  11. static class CommentSortBy<M> implements SortBy<Comment, M> {
  12.  
  13. static final CommentSortBy<Date> CREATION = new CommentSortBy<Date>();
  14. static final CommentSortBy<Integer> VOTES = new CommentSortBy<Integer>();
  15. }
  16.  
  17. static class UserSortBy<M> implements SortBy<User, M> {
  18.  
  19. static final UserSortBy<String> NAME = new UserSortBy<String>();
  20. }
  21.  
  22. static class Query<T> {
  23.  
  24. public <S extends SortBy<T, M>, M> void setSort(S sortBy, M min) {
  25. //Set relevant values
  26. }
  27. }
  28.  
  29. public static void main(String[] args) {
  30.  
  31. new Query<Comment>().setSort(CommentSortBy.CREATION, new Date());
  32. new Query<Comment>().setSort(UserSortBy.NAME, "Joe"); //compiler error
  33. }
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:32: error: method setSort in class Query<T> cannot be applied to given types;
        new Query<Comment>().setSort(UserSortBy.NAME, "Joe"); //compiler error
                            ^
  required: S,M
  found: UserSortBy<String>,String
  reason: inferred type does not conform to declared bound(s)
    inferred: UserSortBy<String>
    bound(s): SortBy<Comment,String>
  where S,M,T are type-variables:
    S extends SortBy<Comment,M> declared in method <S,M>setSort(S,M)
    M extends Object declared in method <S,M>setSort(S,M)
    T extends Object declared in class Query
1 error
stdout
Standard output is empty