News for hackers. Stuff that matters.
Re:Go is boring, and that’s fantastic by ithkuil on Friday July 03, 2020 @10:41AM (#23724442)
imagine an interface{} that can be annotated to say "you can only assign values ofItypes A, B and C to it. E.g. interface(A,B,C){}

Since it's an interface{} it has no behaviour, the only thing you can do is a type assert / type switch.

By extension, you could add some methods: interface(A,B,C){Foo(bool) int} This fails statically unless A, B, and C implement said interface. If they do, then this interface has exactly the same semantics as the normal Go interfaces, except that only types A, B and C can be assigned to it (and not type D even if it implements Foo(bool) int

There are no comments on this comment yet.