Welcome to your new Telegram site. Check out the Getting Started page for information on how to set up your site.

Welcome to my blog. Here are my most recent blog posts:
  • Variance Examples

    February 28, 2014

    Variance Examples

    Hi,

    today I would to introduce scala some. variance examples. Those magic +A -A what is it ?

    I will show by the example, first declaring classes:

    class Boss
    class Worker extends Boss
    class Student extends Worker
    
    class TestClass[A]
    class TestCovariantClass[+A]
    class TestContravariantClass[-A]
    

    Now decalring methods which takes as a param one of our Test classes:

    // here will go Worker class only
    

    def testMethod(x: TestClass[Worker]) {}

    // Worker and Student
    

    def testMethod2(x: TestCovariantClass[Worker]) {}

    // Worker and Boss
    

    def testMethod3(x: TestContravariantClass[Worker]) {}