why not in, out and inout instead of variance?
843793Jul 23 2003 — edited Aug 19 2003Hi,
I'm wondering why the variance is introduced as a language feature instead of parameters' "direction" (I don't remember the proper word) like in, out and inout. It seems to me that the result would be the same, that is you would write Collection<E>.addAll(in Collection<E>) instead of Collection<E>.addAll(Collection<+E>).
This means:
out : use contravariance
in : use covariance
inout : use invariance
It seems easier to specify that a parameter is in or out than specifying its variance. Also, it would be similar to what exists in old languages like Ada and in web services.
It doesn't address the problem of affectation (List<E-> = List<Object>), but there could be some ways of doing this by using in out and inout to tag local variables or fields for example.
What do you think?
Cheers,
Jean-Louis