0
我有一段簡單的代碼如下:VB.NET無法轉換類接口
Public Interface ITest(Of T)
Function getObj() As T
End Interface
Public Class clsTest(Of T As {IOrder, New})
Implements ITest(Of T)
Public Function getObj() As T Implements ITest(Of T).getObj
Return New T
End Function
End Class
Public Interface IOrder
Property Name As String
End Interface
Public Class clsOrder
Implements IOrder
Public Property Name As String Implements IOrder.Name
End Class
當我創建另clsTest對象,如:
Dim test As ITest(Of IOrder) = New clsTest(Of clsOrder)
我得到了以下錯誤:
'ConsoleApplication1.clsTest(Of ConsoleApplication1.clsOrder)' cannot be converted to 'ConsoleApplication1.ITest(Of ConsoleApplication1.IOrder)'. Consider changing the 'T' in the definition of 'Interface ITest(Of T)' to an Out type parameter, 'Out T'.
任何人都知道原因?如果我確實要將測試作爲ITest(IOrder)申報,我該如何使其工作?謝謝。
謝謝,Tim。它解決了我的問題。 – FrankS