Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Covariance Contravariance and Invariance

 
Sujoy Mukherjee
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
can you please explain me the terms Covariance Contravariance and Invariance with some examples?
 
Winston Gutkowski
Bartender
Pie
Posts: 10243
58
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sujoy Mukherjee
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The page cited already has examples in Java as well as other languages.
 
Sujoy Mukherjee
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well to me those examples were not very clear.
Any other examples please?
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic