--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/4e25a228-4c96-44ba-b33a-bbde3460ea2ao%40googlegroups.com.
func Do(type T io.Reader)(r T) {
switch r.(type) {
case io.ReadCloser:
fmt.Println("ReadCloser")
}
}
prog.go2:19:9: r (variable of type T) is not an interface type
Two kind of interfaces appear, where one cannot be used anywhere except a contract: https://go2goplay.golang.org/p/rYOD-n_mV9U
There's a confusion between an interface used as a contract and an interface. People think if they have interface contract their type is an interface (it is not of course): https://www.reddit.com/r/golang/comments/hamaxm/few_things_on_generics_go_the_unwritten_parts/fv66zp8/?context=3. A brainless example of course, but still an example.
If fields will be allowed to be a part of contract (limiting allowed types to structs having some set of fields of certain types) the difference between interfaces and interfaces for contracts will grow even bigger. I see lots of questions like fron ones who just start learning Go "why can't I use a pure field interface as a function parameter type?"
contract also meant a built-in mechanism of type bounding, with interfaces you need to promote each type exclusively, the increased signature size is the consequence of this. Remeber, with contracts you may put a constraint on each of the parameter types and with an interface you should write them all.
interface flood. There's a possibility to use them as an variable/paremeter/return value type although they are only needed for a generic contract.