java - Extending a class in the method signature -
can explain does? generics question since i'm learning in java tagged java.
public static <t extends comparable<? super t>> void quicksort(t[] list) {...}
what don't understand part: <t extends comparable<? super t>>
i have tried looking @ this doesn't seem explain in clear way.
my guess is: genetic type t extends comparable interface requires generic type superclass of generic type. don't understand this.
example:
public class x implements comparable<x> { }
the class x
implements comparable
satisfies extends comparable
, generic parameter of comparable
x
because x
super
x
(java generics super keyword)
another example:
public class y {} public class x extends y implements comparable<y> { }
another example:
public class x implements comparable<object> { }
but won't work:
public class {} public class x implements comparable<a> { }
as class x
comparable objects not in it's inheritance hierarchy.
the sorting algorithm going call x.compareto(y)
, needs know @ compile time that valid.
Comments
Post a Comment