Generic Interface missing implementation

80 views Asked by At

I have a generic interface, even if I state the type when I implement it, it says the implemented classes misses all implementation of members.

The interface

Interface IBuilder(Of T)
    Function Number(ByVal literal As String) As T
End Interface

The implement

Class BracketsBuilder
    Implements IBuilder(Of String)
    Public Function Number(number__1 As String) As String
        Return number__1
    End Function
End Class

When I try to run the code, I get

Class 'BracketsBuilder' must implement 'Function Number(literal As String) As String' for interface 'IBuilder(Of String)'.

1

There are 1 answers

0
Blackwood On BEST ANSWER

You need to indicate on the declaration of the Number function that it is the implementation of the Number Function defined in the Interface

Interface IBuilder(Of T)
    Function Number(ByVal literal As String) As T
End Interface

Class BracketsBuilder
    Implements IBuilder(Of String)

    Public Function Number(number__1 As String) As String Implements IBuilder(Of String).Number
        Return number__1
    End Function
End Class

If you type

Class BracketsBuilder
    Implements IBuilder(Of String)

and then hit enter, Visual Studio will add the Function declaration for you.