tag:blogger.com,1999:blog-4177053433240488765.post6445208020942374185..comments2024-03-28T11:13:35.478+01:00Comments on Coding time - Martin Konicek: Covariance and contravariance - simple explanationMartin Konicekhttp://www.blogger.com/profile/13169352488655771114noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-4177053433240488765.post-46476837524199609612016-01-07T12:44:48.132+01:002016-01-07T12:44:48.132+01:00Thank you! :)Thank you! :)Martin Konicekhttps://www.blogger.com/profile/13169352488655771114noreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-88630869388108631422016-01-07T12:42:56.125+01:002016-01-07T12:42:56.125+01:00Thank you! :)Thank you! :)Martin Konicekhttps://www.blogger.com/profile/13169352488655771114noreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-14180591896319300162016-01-07T01:33:16.212+01:002016-01-07T01:33:16.212+01:00Years old and still one of the better explanations...Years old and still one of the better explanations on the internet. I like in particular the +A and -A annotation of the two, it makes it much more readable than Java's ? super A and ? extends AAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-63689636229421999952013-05-20T18:59:08.717+02:002013-05-20T18:59:08.717+02:00Thanks, so useful!Thanks, so useful!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-52343617733147310462013-02-22T01:17:31.497+01:002013-02-22T01:17:31.497+01:00man I love this explanation, very clear,concise an...man I love this explanation, very clear,concise and simple language, thanks so much...I hope many future post about the scala "hard parts"..thanks!!! Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-3639190274441059602011-05-18T21:16:21.868+02:002011-05-18T21:16:21.868+02:00@Mike: You are welcome. 852 pages is a lot. I woul...@Mike: You are welcome. 852 pages is a lot. I would skim through it and read only the most interesting parts. It seems to me that some books could be made much shorter while providing the same information if the author really tried to be concise.<br />Maybe you will also like this: http://aperiodic.net/phil/scala/s-99/Martin Konicekhttps://www.blogger.com/profile/13169352488655771114noreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-22215961320196923032011-05-18T18:01:15.863+02:002011-05-18T18:01:15.863+02:00class Juice
class MysticJuice extends Juice
class ...class Juice<br />class MysticJuice extends Juice<br />class Foodstuff<br />class Fruit extends Foodstuff<br /><br />class Squeezer {<br /> Juice squeeze(Fruit)<br />}<br />class SpecialSqueezer extends Squeezer {<br /> MysticJuice squeeze(Foodstuff)<br />}<br /><br />Covariance/Contravariance is about type safety. What are type-compatible changes/variations when subclassing/specializing an API?<br /><br />In my example there is a Squeezer and a SpecialSqueezer. SpecialSqueezer has widened the squeeze input parameter type from Fruit to Foodstuff. You can still put Fruits in the SpecialSqueezer. So contravariant changes are type-safe for input types.<br /><br />SpecialSqueezer has narrowed the squeeze return type from Juice to MysticJuice. No problem since you can treat MysticJuice as Juice. Conclusion: covariant changes are type-safe for output types.shoggnoreply@blogger.comtag:blogger.com,1999:blog-4177053433240488765.post-35324320769669619542011-05-18T17:00:27.521+02:002011-05-18T17:00:27.521+02:00I am learning scala and find a simple command line...I am learning scala and find a simple command line demonstration of subtle idea very motivating.<br />I think I will close the 852 page book for a while and play.<br />Thanks for the posting.<br /><br /> -- Mike Treselertreshttps://www.blogger.com/profile/14619556535005597982noreply@blogger.com