3 ms·
Let's say that I have an interface called Sortable, so I design my data structure to accept and return Sortables. I can insert any Sortable into it. When I get
by oppositelock 8y ago
Let's say that I have an interface called Sortable, so I design my data structure to accept and return Sortables. I can insert any Sortable into it. When I get the Sortable in a future lookup, I don't know its type. I have to use reflection to error check.
With generics, I could create a generic data structure which is strongly typed - what goes in is what comes out.
Right now, the way to ensure that is to wrap your data structure in something that converts those Sortables into specific classes, say PatientRecords.
Interfaces are wonderful, I like working in Go more than any other language so far, but they have their limitations.