A Team Game

This weekend saw the return of Cristiano Ronaldo to Manchester United, after more than a decade away. In debates of Messi vs. Ronaldo, a part-Argentinian friend of mine used to say that Ronaldo was…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Changes to interfaces in Go1.14

Go Gopher by Renee French

Keeping up with their six-monthly release schedule, Go 1.14 is just around the corner. There’s quite a few changes such as a faster hash function, and the removal of SSLv3 (which is a breaking change).

But one that I’ll focus on in this post is a change to the core language, namely how interfaces work. Before Go 1.14, you could not have overlapping interfaces. If you’d compose an interface, and your ‘base interfaces’ have a similar function, you’d get the error:

For example, if you have two simple interfaces:

You can create a struct that satisfies both interfaces at the same time, without an issue:

Which means S implements both A and B.

Yet, if we’d create an interface that is a composite of A and B, we’ll get compile-time failures.

As of Go 1.14, creating such composite interfaces will be possible (as long as the functions hold the same signature). So this will still fail:

At this point, the function signature of DoX() is different for interface A and B which is an actual problem.

Personally I’m quite happy with this change, I consider it a bug that this did not work in earlier versions of Go as there would never be any ambiguity when the function signature is the same.

After which you can use the go1.14beta1 command as a replacement for the usual go command. Thus to run the code you use go1.14beta1 run main.go 😉

If you liked this post and 💙 Go as well, consider:

Add a comment

Related posts:

The first week of studying

A friend of mine told me that the first week and the welcome week in the university will be the best time in your university life. However, it was a great week! We visited another city (it is not…

Perspective

What do you see in this image? Death? Last summer’s lavender destroyed by winter? (The latter is closer but still wrong.) When enough snow finally melts that I can see the soil, I can also see the…

Learn How to Dominate Your Competition in the Search Engines

When it comes to how to dominate your competition, Search engine marketing (SEM) is a form of online marketing that uses paid advertising to improve the visibility of a website in search engine…