Can you explain the Go interfaces?

I do not get integer types + Model interface (which replaces classes in other languages). If theres a simple way that you could explain what they are about, it will really be appreciated.

+7
source share
2 answers

Go interfaces have a statically verified duck print.

The difference between pure C ++ virtual classes or interfaces in java is that you do not declare an interface in a class that implements the interface, but in a method that receives the interface.

For example, I can create an interface using the Read and Write method and call it ThingsDustinReadsAndWrites and have a function called doReadsAndWrites(rr ThingsDustinReadsAndWrites . This can, in turn, get a built-in http.ClientConn that never heard of my interface, but implements it because he has these methods.

+4
source
+5
source

All Articles