Skip to content

Commit

Permalink
feat(basic): add ger
Browse files Browse the repository at this point in the history
  • Loading branch information
shgopher committed Jan 30, 2024
1 parent e8cafca commit 0182cf6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions 基础/泛型/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func Get[T Writer](v T) {
v.hi()
}
```
### 泛型是类型,约束是类型的约束

请认识到,泛型是一种类型,约束是一种类型的约束,请不要把约束当作泛型。
```go
Expand All @@ -66,7 +67,7 @@ type st interface{
~string | ~int
}
```

### 约束的嵌套
约束跟接口是一样的也是可以嵌套的

```go
Expand Down Expand Up @@ -96,7 +97,7 @@ type NumericAbs[T any] interface {
}
```
上面的类型意思是满足数字类型,下面的意思是满足这个方法,所以最终实现这个约束的对象就是一个数字类型,并且实现了这个接口的 `Abs()T` 方法。

## 泛型
当结构体中使用泛型的时候,泛型不能直接作为嵌入使用
```go
type Lockable[T any] struct {
Expand Down

0 comments on commit 0182cf6

Please sign in to comment.