0

First of all, happy new year to everyone ! I would like to write a method with a multiple bounds parameter like that:

public static void max(List<? extends Number & Comparable<?>> list)

But unfortunately this code does not compile, could someone explain to me why writing a wilcard parameter with multiple bounds is not possible ?

Thanks

valoo86
  • 23
  • 2
  • It's not possible because it's not defined as part of the language, just like the other infinitely many things which are not possible because they are not part of the language. – Michael Jan 18 '21 at 17:42
  • That isn't a useful wildcard anyway; you need the "comparable to" to be the same as the kind of thing in the list. – chrylis -cautiouslyoptimistic- Jan 18 '21 at 17:42
  • 2
    You probably want a type parameter `T extends Number & Comparable super T>` and make a `List`. – user Jan 18 '21 at 18:08

0 Answers0