|
|
|
|
|
by RHSeeger
4398 days ago
|
|
Is it possible to indicate, in an interface, that it's not a structural type? Ie, that classes need to specifically indicate they implement it to be considered it's type? For example, the HtmlString interface could require only "toString" as a method, but not everything that has that method should be considered that type. |
|
Rather than having a class implement HtmlString as a way to specify that its "toString" method works differently to the usual or expected way for a method of that signature, you can instead write a "toHtmlString" which is more clear. Reading code as "myObject.toString()" vs "myObject.toHtmlString()" is better than having to check the class signature for a special contract pertaining to general-looking method names.