Abstract type: Difference between revisions
→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)"
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
|||
Line 3,220:
End Interface</syntaxhighlight>
=={{header|V (Vlang)}}==
{{trans|go}}
A variable of an interface type can hold a value of any type that implements the methods that are specified in the interface. You don't need to explicitly "declare" that the type "implements" the interface or anything like that -- the compatibility is purely structural based on the methods.
Line 3,228:
In the following example, the Dog and Cat types both satisfy the Beast interface because they each have the specified methods. The ''bprint'' function can print details for any Beast.
<syntaxhighlight lang="v (vlang)">interface Beast {
kind() string
name() string
|