I was reading an interview with Joshua Bloch in Coders at Work, where he lamented the introduction of generics in Java 5. He doesn\'t like the specific implementation largel
.net already has the equivalent of wildcards, more logically named generic type constraints, you can do what you describe with no problems
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
List a = new List();
List b = new List();
List c = new List();
test(a);
test(b);
test(c);
}
static void test(List a) where T : a
{
return;
}
}
class a
{
}
class b : a
{
}
class c : b
{
}
}
Example 2
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
ICollection src = new List();
ICollection dst = new List();
copyAssets(src, dst);
}
public static void copyAssets(ICollection src, ICollection dst) where T : G {
foreach(T asset in src)
dst.Add(asset);
}
}
public class Asset {}
public class Derivative : Asset {}
public class VanillaOption : Derivative {}
}
This example represents a code conversion from your example in java.
I'm not really in a position to answer the actual question though!