Bound mismatch for generic method from "Java Effective" example rewritten -


class main { public static void main(string[] args) {     list<sub> list = new arraylist<sub>();      sub r = max(list);      system.out.println(r); }  static <t extends comparable<? super t>> t max(list<? extends t> list) {     return null; }  private static class super { }  private static class sub implements comparable<super> {     public int compareto(super o) {         return 0;     } } } 

can tell me why i'm getting compiler error @ line "sub r = max(list)"?

i'm reading java effective book , got at, said, complex method declaration in book. it's max method.

error is:

bound mismatch: "the generic method max(list< ? extends t>) of type main not applicable arguments (list< main.sub>). inferred type main.sub not valid substitute bounded parameter < t extends comparable< ? super t>>" 

your sub class have extend super:

private static class sub extends super implements comparable<super> { 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -