interfaces

package
v0.0.0-...-9d91cd3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountInto

func CountInto(a Appender, start, end int)

CountInto .

func LongEnough

func LongEnough(l Lener) bool

LongEnough .

func Sort

func Sort(data Sorter)

Sort boubble sort

func Test1

func Test1()

Test1 practice 1 The way to Go 接口练习

func Test2

func Test2()

Test2 practice 2 类型断言 判断接口是什么类型 接口就是一个动态类型,即在运行时才检查它的实际类型。

func Test3

func Test3()

Test3 practice 3 类型判断 type-switch type-switch 不允许有 fallthrough

func Test4

func Test4()

Test4 类型断言中的特例,判断该值的类型是否实现了接口。

func Test5

func Test5()

Test5 作用于接口变量上的方法和作用于变量上的方法是不同的。 接口变量中存储的值是不可以寻址的。

func Test6

func Test6()

Test6 sorter 接口

Types

type Appender

type Appender interface {
	Append(int)
}

Appender .

type IntArray

type IntArray []int

IntArray int array

func (IntArray) Len

func (p IntArray) Len() int

func (IntArray) Less

func (p IntArray) Less(i, j int) bool

func (IntArray) Swap

func (p IntArray) Swap(i, j int)

type Lener

type Lener interface {
	Len() int
}

Lener .

type List

type List []int

List .

func (*List) Append

func (l *List) Append(val int)

Append .

func (List) Len

func (l List) Len() int

Len .

type Name

type Name []int

Name 实现 Nameable 接口看下接口类型的变量在内存中的存储 是否是按照对应类型的值和自动反射出来的方法

func (Name) Age

func (n Name) Age(age int) int

Age Nameable function

func (Name) Name

func (n Name) Name(name string) string

Name Nameable function

type Nameable

type Nameable interface {
	Name(name string) string
	Age(age int) int
}

Nameable name interface

type Options

type Options interface {
	// contains filtered or unexported methods
}

Options 可选参数接口

type Sorter

type Sorter interface {
	Len() int
	Less(i, j int) bool
	Swap(i, j int)
}

Sorter interface 接口中 i,j 表示的是下标

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL