有两个接口
Public Interface IMessage
Sub ShoMessage()
End Interface
Public Interface ITextInfo
ReadOnly Property Text() As String
End Interface
实现这两个接口的类有两个
Public Class Message
Implements IMessage
Public Sub ShoMessage() Implements IMessage.ShoMessage
MsgBox("Message")
End Sub
End Class
Public Class TextInfo
Implements ITextInfo
Public ReadOnly Property Text() As String Implements ITextInfo.Text
Get
Return "TextInfo"
End Get
End Property
End Class
现在有一个第三方的类对这两个类进行操作
Public Class Manager
Public Sub Execute(ByVal obj As Object)
MsgBox("无效的类")
End Sub
Public Sub Execute(ByVal obj As ITextInfo)
MsgBox(obj.Text)
End Sub
Public Sub execute(ByVal obj As IMessage)
obj.ShoMessage()
End Sub
End Class
下面的调用程序。
Sub Main()
Dim m As New Manager
Dim obj As Object = New TextInfo
m.Execute(obj)
obj = New Message
m.Execute(obj)
Console.ReadLine()
End Sub
为什么总是执行到了
Public Sub Execute(ByVal obj As Object)
MsgBox("无效的类")
End Sub
这个方法。
目前我所知道的,如果外部不使用object能正确的找到对应的方法.
如果去掉Public Sub Execute(ByVal obj As Object)方法,也能执行正确,如果我目前需要有Public Sub Execute(ByVal obj As Object)这样一个方法,也能执行相应接口的方法啊。