Forums Register Login

Covariance Contravariance and Invariance

+Pie Number of slices to send: Send
Hello friends,
can you please explain me the terms Covariance Contravariance and Invariance with some examples?
+Pie Number of slices to send: Send
 

Sujoy Mukherjee wrote:can you please explain me the terms Covariance Contravariance and Invariance with some examples?


Google is your friend.

However, very simply:
Covariance = narrowing conversion.
Contravariance = widening conversion.
Invariance (in this context) = not convertible.

This page probably explains it better.

Winston
+Pie Number of slices to send: Send
Dear Winston,
thanks for replying.
I have already visited the page.
However still those topics are not clear to me.
It would be better if you could provide some code examples.....may be a real life scenario.
+Pie Number of slices to send: Send
The page cited already has examples in Java as well as other languages.
+Pie Number of slices to send: Send
Well to me those examples were not very clear.
Any other examples please?
+Pie Number of slices to send: Send
The way things work around here, it's probably better for you to post some examples of what you think is representative of each concept and then we'll offer opinions of whether you're on track or not.
1
+Pie Number of slices to send: Send
That article looks extremely comprehensive to me. And as far as I can see it does have examples to illustrate the concepts. I don't see the need for any more examples. Especially as it seems like you're just going to ask for more examples even if we do produce some.

So let's turn it over to you. You've read the article. And your knowledge is still incomplete. So why don't you ask a specific question about something which you don't understand yet? Better still, produce an example and ask a specific question about it.
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1909 times.
Similar Threads
How do you create an array of typesafe-collections?
Covariance, Method Overriding and Return Type
Why String class immutable
Regarding Polymorphism
Covariant problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:35:18.