What's wrong with this generic type?
I love mysteries. However, this one is pretty simple.
Q: What is wrong with the following generic type?
VB.NET
Public Class BaseClass(Of K, V)
End Class
Public Class SubClass1
Inherits BaseClass(Of K, V)
End Class
Public Class SubClass2
Inherits BaseClass(Of Integer, Long)
End Class
C#
public class BaseClass<K, V> { }
public class SubClass1 : BaseClass<K, V> { }
public class SubClass2 : BaseClass<int, long> { }
A: If you were to compile the above code, the compiler would generate an error for SubClass1. SubClass1 is an open type and generates no point of reference for types K and V. SubClass2 is a constructed type and, since it has type arguments declared, will compile.
Similar Posts
- Generic Sub Classes
- What sets C++ Templates and .NET Generics apart?
- What does the ` character stand for?




