title: Generics, Covariance/Contravariance, etc
body: <p>So I have some Java code that makes extensive use of generics that compiles just fine. I ported it over to C# as follows:
      </p>
  
  <pre><code>interface IFoo1 { }
  interface IFoo2 { }
  
  interface IBar&lt;T, K&gt;
      where T : IFoo1
      where K : IFoo2 {
      List&lt;T&gt; GetFoo1s();
      void AddAFoo1(T foo1);
  
      List&lt;K&gt; GetFoo2s();
      void AddAFoo2(K foo2);
  }
  
  interface IBlip&lt;T&gt;
      where T : IBar&lt;IFoo1, IFoo2&gt; {
      T DoBlip(string input);
      void DoBlip2(T input);
  }
  
  interface IConverter&lt;T, K&gt;
      where T : IBar&lt;IFoo1, IFoo2&gt;
      where K : IBar&lt;IFoo1, IFoo2&gt; {
      K Convert(T input);
  }
  
  class FooA1 : IFoo1 { }
  class FooB1 : IFoo1 { }
  
  class FooA2 : IFoo2 { }
  class FooB2 : IFoo2 { }
  
  class BarA : IBar&lt;FooA1, FooA2&gt; {
      public List&lt;FooA1&gt; GetFoo1s() { return null;  }
      public void AddAFoo1(FooA1 foo1) { }
      public List&lt;FooA2&gt; GetFoo2s() { return null; }
      public void AddAFoo2(FooA2 foo2) { }
  }
  
  class BarB : IBar&lt;FooB1, FooB2&gt; {
      public List&lt;FooB1&gt; GetFoo1s() { return null; }
      public void AddAFoo1(FooB1 foo1) { }
      public List&lt;FooB2&gt; GetFoo2s() { return null; }
      public void AddAFoo2(FooB2 foo2) { }
  }
  
  class BlipA : IBlip&lt;BarA&gt; {
      public BarA DoBlip(string input) { return null; }
      public void DoBlip2(BarA input) { }
  }
  
  class BlipB : IBlip&lt;BarB&gt; {
      public BarB DoBlip(string input) { return null; }
      public void DoBlip2(BarB input) { }
  }
  
  class ConverterImplementation : IConverter&lt;BarA, BarB&gt; {
      public BarB Convert(BarA input) {
          return null;
      }
  }
  </code></pre>
  
  <p>When I compile this, it complains that, for example, with the ConverterImplementation, that BarA cannot be implicitly converted to IBar. I guess there's something that I'm fundamentally missing here. Could someone shed some light on it? Thanks.</p>