考虑:
Public MustInherit Class Column
Public ReadOnly Property ReturnSomethingUseful() As Object
Get
'return something useful
End Get
End Property
End Class
Public Class TypedColumn(Of T)
Inherits Column
Public Overrides ReadOnly Property ReturnSomethingUseful() As T
Get
'return the same something useful, but as type T
Return MyBase.ReturnSomethingUseful()
End Get
End Property
End Class
但这会产生以下错误:
Public Overrides Function ReturnSomethingUseful(sValue As String) As Boolean' 不能覆盖'Public Overridable Function ReturnSomethingUseful(sValue As String) As Object',因为它们的返回类型不同。
我接受你不能这样做,但我希望能够保留我正在尝试做的事情的语义,即有一个处理 的无类型版本Object
,但派生类中的类型版本知道具体的类型T
。有没有办法做到这一点?