• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Covariance Contravariance and Invariance

 
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends,
can you please explain me the terms Covariance Contravariance and Invariance with some examples?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 17345
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well to me those examples were not very clear.
Any other examples please?
 
Junilu Lacar
Sheriff
Posts: 17345
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 27452
88
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I once met a man from Nantucket. He had a tiny ad
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic