Standard library / reflect

reflect.MakeChan()

Creates a non-nil bidirectional channel of the given channel type and buffer size. Expected stdout: '8\n'.

Formal Syntax & Structure

go syntaxgo
func MakeChan(typ Type, buffer int) Value

Parameters & Attributes

NameTypeDescription
typTypeRuntime type descriptor for the new value.
bufferintNonnegative channel buffer capacity.

Return Value

Value

Creates a non-nil bidirectional channel of the given channel type and buffer size.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  v := reflect.MakeChan(reflect.TypeFor[chan int](), 1)  v.Send(reflect.ValueOf(8))  x, _ := v.Recv()  fmt.Println(x.Int())}
Go Reference