![](/img/trans.png)
[英]Is there a Go generic type constraint that captures the ability to use a type as a key in a map?
[英]How to use an interface containing type constraint as generic
我想要一片帶有泛型的結構。 泛型是具有類型約束的接口。
type constraint interface {
int32 | uint32
}
type a[T constraint] struct {
something T
}
type b struct {
as []a[constraint] // doesn't work
}
我該怎么做才能同時使用a[int32]
和a[uint32]
作為b.as
中的元素?
按照我提議的方式,我想做的事是不可能的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.