I have a copy function that I'd like to override in subclasses to return the type of the subclass. Here are my interfaces:
Public Interface IBase(Of T)
Function Copy() As T
End Interface
Public Interface ICar
Inherits IBase(Of ICar)
End Interface
Public Interface IToyota
Inherits ICar
End Interface
And here are my classes. As you can see, when Car overrides Copy it return ICar which is what I want. But when Toyota overrides Copy it also wants to return ICar instead of IToyota. How do I write it to return IToyota?
Public MustInherit Class Base(Of T)
Implements IBase(Of T)
Protected MustOverride Function Copy() As T Implements IBase(Of T).Copy
End Class
Public Class Car
Inherits Base(Of ICar)
Implements ICar
Protected Overrides Function Copy() As ICar
Return Nothing //'TODO: Implement Copy
End Function
End Class
Public Class Toyota
Inherits Car
Implements IToyota
Protected Overrides Function Copy() As IToyota Implements IToyota.Copy
//'I want this to return IToyota, but gives me a compile error
End Function
End Class