Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

why not in, out and inout instead of variance?

843793Jul 23 2003 — edited Aug 19 2003
Hi,

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





Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2003
Added on Jul 23 2003
4 comments
119 views