This means then that to use a subtype for the type argument, it is safe for the function to READ the argument, but unsafe to WRITE to it.
Conversely. If the function accepted List<Integer>, but was theoretically given List<Number>, WRITING would be safe, but READING wouldn't. Given this, it doesn't matter how it's done, both scenarios are prone to error, and the only options are to either accept that or disallow it. On 29 Apr 2016 5:11 p.m., "Rowan Collins" <rowan.coll...@gmail.com> wrote: > Dominic Grostate wrote on 29/04/2016 16:59: > >> >> After reading your email again, I find myself agreeing. This is because >> I don't consider List<Integer> to be a subtype of List<Number>. >> >> LinkedList<Number> would be a subtype of List<Number>, but inheritance >> doesn't really extend any further beyond that, for the reason you have >> illustrated. >> >> > > Precisely, the rules for variance of the type parameter <Number> are not > the same as the rules for variance of the generic class List itself. The > exact variance that you want is different in different situations, so the > safest assumption the language can make is to make the type parameter > invariant by default, and then possibly have a syntax for you to state that > you want covariance or contravariance in specific situations. > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >