File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Covariance Contravariance and Invariance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Covariance Contravariance and Invariance" Watch "Covariance Contravariance and Invariance" New topic
Author

Covariance Contravariance and Invariance

Sujoy Mukherjee
Ranch Hand

Joined: Dec 31, 2005
Posts: 51

Hello friends,
can you please explain me the terms Covariance Contravariance and Invariance with some examples?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7772
    
  21

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Sujoy Mukherjee
Ranch Hand

Joined: Dec 31, 2005
Posts: 51

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

Joined: Feb 26, 2001
Posts: 4462
    
    6

The page cited already has examples in Java as well as other languages.


Junilu - [How to Ask Questions] [How to Answer Questions]
Sujoy Mukherjee
Ranch Hand

Joined: Dec 31, 2005
Posts: 51

Well to me those examples were not very clear.
Any other examples please?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

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
Bartender

Joined: Oct 14, 2005
Posts: 18563
    
    8

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Covariance Contravariance and Invariance