Namespace: go.std.reflect
v1.0Contents
Summary
Provides a low-level interface to the reflect package.
Package reflect implements run-time reflection, allowing a program to
manipulate objects with arbitrary types. The typical use is to take a value
with static type interface{} and extract its dynamic type information by
calling TypeOf, which returns a Type.
A call to ValueOf returns a Value representing the run-time data.
Zero takes a Type and returns a Value representing a zero value
for that type.
See "The Laws of Reflection" for an introduction to reflection in Go:
https://golang.org/doc/articles/laws_of_reflection.html
Index
- *ChanDir
- *Kind
- *MapIter
- *Method
- *SelectCase
- *SelectDir
- *SliceHeader
- *StringHeader
- *StructField
- *StructTag
- *Value
- *ValueError
- AppendSlice
- Array
- ArrayOf
- Bool
- BothDir
- Chan
- ChanDir
- ChanOf
- Complex128
- Complex64
- Copy
- DeepEqual
- Float32
- Float64
- Func
- FuncOf
- Indirect
- Int
- Int16
- Int32
- Int64
- Int8
- Interface
- Invalid
- Kind
- MakeChan
- MakeMap
- MakeMapWithSize
- MakeSlice
- Map
- MapIter
- MapOf
- Method
- New
- NewAt
- Pointer
- PointerTo
- Ptr
- PtrTo
- RecvDir
- Select
- SelectCase
- SelectDefault
- SelectDir
- SelectRecv
- SelectSend
- SendDir
- Slice
- SliceHeader
- SliceOf
- String
- StringHeader
- Struct
- StructField
- StructOf
- StructTag
- Type
- TypeOf
- Uint
- Uint16
- Uint32
- Uint64
- Uint8
- Uintptr
- UnsafePointer
- Value
- ValueError
- ValueOf
- VisibleFields
- Zero
- arrayOfChanDir
- arrayOfKind
- arrayOfMapIter
- arrayOfMethod
- arrayOfSelectCase
- arrayOfSelectDir
- arrayOfSliceHeader
- arrayOfStringHeader
- arrayOfStructField
- arrayOfStructTag
- arrayOfType
- arrayOfValue
- arrayOfValueError
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
Array
GoObject v1.0 -
Bool
GoObject v1.0 -
BothDir
GoObject v1.0chan
-
Chan
GoObject v1.0 -
Complex128
GoObject v1.0 -
Complex64
GoObject v1.0 -
Float32
GoObject v1.0 -
Float64
GoObject v1.0 -
Func
GoObject v1.0 -
Int
GoObject v1.0 -
Int16
GoObject v1.0 -
Int32
GoObject v1.0 -
Int64
GoObject v1.0 -
Int8
GoObject v1.0 -
Interface
GoObject v1.0 -
Invalid
GoObject v1.0 -
Map
GoObject v1.0 -
Pointer
GoObject v1.0 -
Ptr
GoObject v1.0Ptr is the old name for the Pointer kind.
-
RecvDir
GoObject v1.0<-chan
-
SelectDefault
GoObject v1.0default
-
SelectRecv
GoObject v1.0case <-Chan:
-
SelectSend
GoObject v1.0case Chan <- Send
-
SendDir
GoObject v1.0chan<-
-
Slice
GoObject v1.0 -
String
GoObject v1.0 -
Struct
GoObject v1.0 -
Uint
GoObject v1.0 -
Uint16
GoObject v1.0 -
Uint32
GoObject v1.0 -
Uint64
GoObject v1.0 -
Uint8
GoObject v1.0 -
Uintptr
GoObject v1.0 -
UnsafePointer
GoObject v1.0
Functions, Macros, and Special Forms
-
AppendSlice
Function v1.0(AppendSlice s t)
AppendSlice appends a slice t to a slice s and returns the resulting slice.
The slices s and t must have the same element type.
Go input arguments: (s Value, t Value)
Go returns: Value
Joker input arguments: [^Value s, ^Value t]
Joker returns: ^Value -
ArrayOf
Function v1.0(ArrayOf length elem)
ArrayOf returns the array type with the given length and element type.
For example, if t represents int, ArrayOf(5, t) represents [5]int.
If the resulting type would be larger than the available address space,
ArrayOf panics.
Go input arguments: (length int, elem Type)
Go returns: Type
Joker input arguments: [^Int length, ^Type elem]
Joker returns: ^Type -
ChanOf
Function v1.0(ChanOf dir t)
ChanOf returns the channel type with the given direction and element type.
For example, if t represents int, ChanOf(RecvDir, t) represents <-chan int.
The gc runtime imposes a limit of 64 kB on channel element types.
If t's size is equal to or exceeds this limit, ChanOf panics.
Go input arguments: (dir ChanDir, t Type)
Go returns: Type
Joker input arguments: [^ChanDir dir, ^Type t]
Joker returns: ^Type -
Copy
Function v1.0(Copy dst src)
Copy copies the contents of src into dst until either
dst has been filled or src has been exhausted.
It returns the number of elements copied.
Dst and src each must have kind Slice or Array, and
dst and src must have the same element type.
As a special case, src can have kind String if the element type of dst is kind Uint8.
Go input arguments: (dst Value, src Value)
Go returns: int
Joker input arguments: [^Value dst, ^Value src]
Joker returns: ^Int -
DeepEqual
Function v1.0(DeepEqual x y)
DeepEqual reports whether x and y are “deeply equal,” defined as follows.
Two values of identical type are deeply equal if one of the following cases applies.
Values of distinct types are never deeply equal.
Array values are deeply equal when their corresponding elements are deeply equal.
Struct values are deeply equal if their corresponding fields,
both exported and unexported, are deeply equal.
Func values are deeply equal if both are nil; otherwise they are not deeply equal.
Interface values are deeply equal if they hold deeply equal concrete values.
Map values are deeply equal when all of the following are true:
they are both nil or both non-nil, they have the same length,
and either they are the same map object or their corresponding keys
(matched using Go equality) map to deeply equal values.
Pointer values are deeply equal if they are equal using Go's == operator
or if they point to deeply equal values.
Slice values are deeply equal when all of the following are true:
they are both nil or both non-nil, they have the same length,
and either they point to the same initial entry of the same underlying array
(that is, &x[0] == &y[0]) or their corresponding elements (up to length) are deeply equal.
Note that a non-nil empty slice and a nil slice (for example, []byte{} and []byte(nil))
are not deeply equal.
Other values - numbers, bools, strings, and channels - are deeply equal
if they are equal using Go's == operator.
In general DeepEqual is a recursive relaxation of Go's == operator.
However, this idea is impossible to implement without some inconsistency.
Specifically, it is possible for a value to be unequal to itself,
either because it is of func type (uncomparable in general)
or because it is a floating-point NaN value (not equal to itself in floating-point comparison),
or because it is an array, struct, or interface containing
such a value.
On the other hand, pointer values are always equal to themselves,
even if they point at or contain such problematic values,
because they compare equal using Go's == operator, and that
is a sufficient condition to be deeply equal, regardless of content.
DeepEqual has been defined so that the same short-cut applies
to slices and maps: if x and y are the same slice or the same map,
they are deeply equal regardless of content.
As DeepEqual traverses the data values it may find a cycle. The
second and subsequent times that DeepEqual compares two pointer
values that have been compared before, it treats the values as
equal rather than examining the values to which they point.
This ensures that DeepEqual terminates.
Go input arguments: (x any, y any)
Go returns: bool
Joker input arguments: [^GoObject x, ^GoObject y]
Joker returns: ^Boolean -
FuncOf
Function v1.0(FuncOf in out variadic)
FuncOf returns the function type with the given argument and result types.
For example if k represents int and e represents string,
FuncOf([]Type{k}, []Type{e}, false) represents func(int) string.
The variadic argument controls whether the function is variadic. FuncOf
panics if the in[len(in)-1] does not represent a slice and variadic is
true.
Go input arguments: (in []Type, out []Type, variadic bool)
Go returns: Type
Joker input arguments: [^arrayOfType in, ^arrayOfType out, ^Boolean variadic]
Joker returns: ^Type -
Indirect
Function v1.0(Indirect v)
Indirect returns the value that v points to.
If v is a nil pointer, Indirect returns a zero Value.
If v is not a pointer, Indirect returns v.
Go input arguments: (v Value)
Go returns: Value
Joker input arguments: [^Value v]
Joker returns: ^Value -
MakeChan
Function v1.0(MakeChan typ buffer)
MakeChan creates a new channel with the specified type and buffer size.
Go input arguments: (typ Type, buffer int)
Go returns: Value
Joker input arguments: [^Type typ, ^Int buffer]
Joker returns: ^Value -
MakeMap
Function v1.0(MakeMap typ)
MakeMap creates a new map with the specified type.
Go input arguments: (typ Type)
Go returns: Value
Joker input arguments: [^Type typ]
Joker returns: ^Value -
MakeMapWithSize
Function v1.0(MakeMapWithSize typ n)
MakeMapWithSize creates a new map with the specified type
and initial space for approximately n elements.
Go input arguments: (typ Type, n int)
Go returns: Value
Joker input arguments: [^Type typ, ^Int n]
Joker returns: ^Value -
MakeSlice
Function v1.0(MakeSlice typ len cap)
MakeSlice creates a new zero-initialized slice value
for the specified slice type, length, and capacity.
Go input arguments: (typ Type, len int, cap int)
Go returns: Value
Joker input arguments: [^Type typ, ^Int len, ^Int cap]
Joker returns: ^Value -
MapOf
Function v1.0(MapOf key elem)
MapOf returns the map type with the given key and element types.
For example, if k represents int and e represents string,
MapOf(k, e) represents map[int]string.
If the key type is not a valid map key type (that is, if it does
not implement Go's == operator), MapOf panics.
Go input arguments: (key Type, elem Type)
Go returns: Type
Joker input arguments: [^Type key, ^Type elem]
Joker returns: ^Type -
New
Function v1.0(New typ)
New returns a Value representing a pointer to a new zero value
for the specified type. That is, the returned Value's Type is PointerTo(typ).
Go input arguments: (typ Type)
Go returns: Value
Joker input arguments: [^Type typ]
Joker returns: ^Value -
NewAt
Function v1.0(NewAt typ p)
NewAt returns a Value representing a pointer to a value of the
specified type, using p as that pointer.
Go input arguments: (typ Type, p unsafe.Pointer)
Go returns: Value
Joker input arguments: [^Type typ, ^go.std.unsafe/Pointer p]
Joker returns: ^Value -
PointerTo
Function v1.0(PointerTo t)
PointerTo returns the pointer type with element t.
For example, if t represents type Foo, PointerTo(t) represents *Foo.
Go input arguments: (t Type)
Go returns: Type
Joker input arguments: [^Type t]
Joker returns: ^Type -
PtrTo
Function v1.0(PtrTo t)
PtrTo returns the pointer type with element t.
For example, if t represents type Foo, PtrTo(t) represents *Foo.
PtrTo is the old spelling of PointerTo.
The two functions behave identically.
Go input arguments: (t Type)
Go returns: Type
Joker input arguments: [^Type t]
Joker returns: ^Type -
Select
Function v1.0(Select cases)
Select executes a select operation described by the list of cases.
Like the Go select statement, it blocks until at least one of the cases
can proceed, makes a uniform pseudo-random choice,
and then executes that case. It returns the index of the chosen case
and, if that case was a receive operation, the value received and a
boolean indicating whether the value corresponds to a send on the channel
(as opposed to a zero value received because the channel is closed).
Select supports a maximum of 65536 cases.
Go input arguments: (cases []SelectCase)
Go returns: (chosen int, recv Value, recvOK bool)
Joker input arguments: [^arrayOfSelectCase cases]
Joker returns: [^Int chosen, ^Value recv, ^Boolean recvOK] -
SliceOf
Function v1.0(SliceOf t)
SliceOf returns the slice type with element type t.
For example, if t represents int, SliceOf(t) represents []int.
Go input arguments: (t Type)
Go returns: Type
Joker input arguments: [^Type t]
Joker returns: ^Type -
StructOf
Function v1.0(StructOf fields)
StructOf returns the struct type containing fields.
The Offset and Index fields are ignored and computed as they would be
by the compiler.
StructOf currently does not generate wrapper methods for embedded
fields and panics if passed unexported StructFields.
These limitations may be lifted in a future version.
Go input arguments: (fields []StructField)
Go returns: Type
Joker input arguments: [^arrayOfStructField fields]
Joker returns: ^Type -
TypeOf
Function v1.0(TypeOf i)
TypeOf returns the reflection Type that represents the dynamic type of i.
If i is a nil interface value, TypeOf returns nil.
Go input arguments: (i any)
Go returns: Type
Joker input arguments: [^GoObject i]
Joker returns: ^Type -
ValueOf
Function v1.0(ValueOf i)
ValueOf returns a new Value initialized to the concrete value
stored in the interface i. ValueOf(nil) returns the zero Value.
Go input arguments: (i any)
Go returns: Value
Joker input arguments: [^GoObject i]
Joker returns: ^Value -
VisibleFields
Function v1.0(VisibleFields t)
VisibleFields returns all the visible fields in t, which must be a
struct type. A field is defined as visible if it's accessible
directly with a FieldByName call. The returned fields include fields
inside anonymous struct members and unexported fields. They follow
the same order found in the struct, with anonymous fields followed
immediately by their promoted fields.
For each element e of the returned slice, the corresponding field
can be retrieved from a value v of type t by calling v.FieldByIndex(e.Index).
Go input arguments: (t Type)
Go returns: []StructField
Joker input arguments: [^Type t]
Joker returns: ^arrayOfStructField -
Zero
Function v1.0(Zero typ)
Zero returns a Value representing the zero value for the specified type.
The result is different from the zero value of the Value struct,
which represents no value at all.
For example, Zero(TypeOf(42)) returns a Value with Kind Int and value 0.
The returned value is neither addressable nor settable.
Go input arguments: (typ Type)
Go returns: Value
Joker input arguments: [^Type typ]
Joker returns: ^Value
Types
-
*ChanDir
Concrete Type v1.0ChanDir represents a channel type's direction.
-
*Kind
Concrete Type v1.0A Kind represents the specific kind of type that a Type represents.
The zero Kind is not a valid kind.
-
*MapIter
Concrete Type v1.0A MapIter is an iterator for ranging over a map.
See Value.MapRange.
-
Key
Receiver for *MapIter v1.0([])
Key returns the key of iter's current map entry.
-
Next
Receiver for *MapIter v1.0([])
Next advances the map iterator and reports whether there is another
entry. It returns false when iter is exhausted; subsequent
calls to Key, Value, or Next will panic.
-
Reset
Receiver for *MapIter v1.0([v])
Reset modifies iter to iterate over v.
It panics if v's Kind is not Map and v is not the zero Value.
Reset(Value{}) causes iter to not to refer to any map,
which may allow the previously iterated-over map to be garbage collected.
-
Value
Receiver for *MapIter v1.0([])
Value returns the value of iter's current map entry.
-
*Method
Concrete Type v1.0Method represents a single method.
-
*SelectCase
Concrete Type v1.0A SelectCase describes a single case in a select operation.
The kind of case depends on Dir, the communication direction.
If Dir is SelectDefault, the case represents a default case.
Chan and Send must be zero Values.
If Dir is SelectSend, the case represents a send operation.
Normally Chan's underlying value must be a channel, and Send's underlying value must be
assignable to the channel's element type. As a special case, if Chan is a zero Value,
then the case is ignored, and the field Send will also be ignored and may be either zero
or non-zero.
If Dir is SelectRecv, the case represents a receive operation.
Normally Chan's underlying value must be a channel and Send must be a zero Value.
If Chan is a zero Value, then the case is ignored, but Send must still be a zero Value.
When a receive operation is selected, the received Value is returned by Select.
-
*SelectDir
Concrete Type v1.0A SelectDir describes the communication direction of a select case.
-
*SliceHeader
Concrete Type v1.0SliceHeader is the runtime representation of a slice.
It cannot be used safely or portably and its representation may
change in a later release.
Moreover, the Data field is not sufficient to guarantee the data
it references will not be garbage collected, so programs must keep
a separate, correctly typed pointer to the underlying data.
-
*StringHeader
Concrete Type v1.0StringHeader is the runtime representation of a string.
It cannot be used safely or portably and its representation may
change in a later release.
Moreover, the Data field is not sufficient to guarantee the data
it references will not be garbage collected, so programs must keep
a separate, correctly typed pointer to the underlying data.
-
*StructField
Concrete Type v1.0A StructField describes a single field in a struct.
-
*StructTag
Concrete Type v1.0A StructTag is the tag string in a struct field.
By convention, tag strings are a concatenation of
optionally space-separated key:"value" pairs.
Each key is a non-empty string consisting of non-control
characters other than space (U+0020 ' '), quote (U+0022 '"'),
and colon (U+003A ':'). Each value is quoted using U+0022 '"'
characters and Go string literal syntax.
-
*Value
Concrete Type v1.0Value is the reflection interface to a Go value.
Not all methods apply to all kinds of values. Restrictions,
if any, are noted in the documentation for each method.
Use the Kind method to find out the kind of value before
calling kind-specific methods. Calling a method
inappropriate to the kind of type causes a run time panic.
The zero Value represents no value.
Its IsValid method returns false, its Kind method returns Invalid,
its String method returns "<invalid Value>", and all other methods panic.
Most functions and methods never return an invalid value.
If one does, its documentation states the conditions explicitly.
A Value can be used concurrently by multiple goroutines provided that
the underlying Go value can be used concurrently for the equivalent
direct operations.
To compare two Values, compare the results of the Interface method.
Using == on two Values does not compare the underlying values
they represent.
-
*ValueError
Concrete Type v1.0A ValueError occurs when a Value method is invoked on
a Value that does not support it. Such cases are documented
in the description of each method.
-
Error
Receiver for *ValueError v1.0([])
-
ChanDir
Concrete Type v1.0ChanDir represents a channel type's direction.
-
String
Receiver for ChanDir v1.0([])
-
Kind
Concrete Type v1.0A Kind represents the specific kind of type that a Type represents.
The zero Kind is not a valid kind.
-
String
Receiver for Kind v1.0([])
String returns the name of k.
-
MapIter
Concrete Type v1.0A MapIter is an iterator for ranging over a map.
See Value.MapRange.
-
Method
Concrete Type v1.0Method represents a single method.
-
IsExported
Receiver for Method v1.0([])
IsExported reports whether the method is exported.
-
SelectCase
Concrete Type v1.0A SelectCase describes a single case in a select operation.
The kind of case depends on Dir, the communication direction.
If Dir is SelectDefault, the case represents a default case.
Chan and Send must be zero Values.
If Dir is SelectSend, the case represents a send operation.
Normally Chan's underlying value must be a channel, and Send's underlying value must be
assignable to the channel's element type. As a special case, if Chan is a zero Value,
then the case is ignored, and the field Send will also be ignored and may be either zero
or non-zero.
If Dir is SelectRecv, the case represents a receive operation.
Normally Chan's underlying value must be a channel and Send must be a zero Value.
If Chan is a zero Value, then the case is ignored, but Send must still be a zero Value.
When a receive operation is selected, the received Value is returned by Select.
-
SelectDir
Concrete Type v1.0A SelectDir describes the communication direction of a select case.
-
SliceHeader
Concrete Type v1.0SliceHeader is the runtime representation of a slice.
It cannot be used safely or portably and its representation may
change in a later release.
Moreover, the Data field is not sufficient to guarantee the data
it references will not be garbage collected, so programs must keep
a separate, correctly typed pointer to the underlying data.
-
StringHeader
Concrete Type v1.0StringHeader is the runtime representation of a string.
It cannot be used safely or portably and its representation may
change in a later release.
Moreover, the Data field is not sufficient to guarantee the data
it references will not be garbage collected, so programs must keep
a separate, correctly typed pointer to the underlying data.
-
StructField
Concrete Type v1.0A StructField describes a single field in a struct.
-
IsExported
Receiver for StructField v1.0([])
IsExported reports whether the field is exported.
-
StructTag
Concrete Type v1.0A StructTag is the tag string in a struct field.
By convention, tag strings are a concatenation of
optionally space-separated key:"value" pairs.
Each key is a non-empty string consisting of non-control
characters other than space (U+0020 ' '), quote (U+0022 '"'),
and colon (U+003A ':'). Each value is quoted using U+0022 '"'
characters and Go string literal syntax.
-
Get
Receiver for StructTag v1.0([key])
Get returns the value associated with key in the tag string.
If there is no such key in the tag, Get returns the empty string.
If the tag does not have the conventional format, the value
returned by Get is unspecified. To determine whether a tag is
explicitly set to the empty string, use Lookup.
-
Lookup
Receiver for StructTag v1.0([key])
Lookup returns the value associated with key in the tag string.
If the key is present in the tag the value (which may be empty)
is returned. Otherwise the returned value will be the empty string.
The ok return value reports whether the value was explicitly set in
the tag string. If the tag does not have the conventional format,
the value returned by Lookup is unspecified.
-
Type
Abstract Type v1.0Type is the representation of a Go type.
Not all methods apply to all kinds of types. Restrictions,
if any, are noted in the documentation for each method.
Use the Kind method to find out the kind of type before
calling kind-specific methods. Calling a method
inappropriate to the kind of type causes a run-time panic.
Type values are comparable, such as with the == operator,
so they can be used as map keys.
Two Type values are equal if they represent identical types.
-
Align
Method for Type v1.0([])
-
AssignableTo
Method for Type v1.0([u])
-
Bits
Method for Type v1.0([])
-
ChanDir
Method for Type v1.0([])
-
Comparable
Method for Type v1.0([])
-
ConvertibleTo
Method for Type v1.0([u])
-
Elem
Method for Type v1.0([])
-
Field
Method for Type v1.0([i])
-
FieldAlign
Method for Type v1.0([])
-
FieldByIndex
Method for Type v1.0([index])
-
FieldByName
Method for Type v1.0([name])
-
Implements
Method for Type v1.0([u])
-
In
Method for Type v1.0([i])
-
IsVariadic
Method for Type v1.0([])
-
Key
Method for Type v1.0([])
-
Kind
Method for Type v1.0([])
-
Len
Method for Type v1.0([])
-
Method
Method for Type v1.0([arg1])
-
MethodByName
Method for Type v1.0([arg1])
-
Name
Method for Type v1.0([])
-
NumField
Method for Type v1.0([])
-
NumIn
Method for Type v1.0([])
-
NumMethod
Method for Type v1.0([])
-
NumOut
Method for Type v1.0([])
-
Out
Method for Type v1.0([i])
-
PkgPath
Method for Type v1.0([])
-
Size
Method for Type v1.0([])
-
String
Method for Type v1.0([])
-
Value
Concrete Type v1.0Value is the reflection interface to a Go value.
Not all methods apply to all kinds of values. Restrictions,
if any, are noted in the documentation for each method.
Use the Kind method to find out the kind of value before
calling kind-specific methods. Calling a method
inappropriate to the kind of type causes a run time panic.
The zero Value represents no value.
Its IsValid method returns false, its Kind method returns Invalid,
its String method returns "<invalid Value>", and all other methods panic.
Most functions and methods never return an invalid value.
If one does, its documentation states the conditions explicitly.
A Value can be used concurrently by multiple goroutines provided that
the underlying Go value can be used concurrently for the equivalent
direct operations.
To compare two Values, compare the results of the Interface method.
Using == on two Values does not compare the underlying values
they represent.
-
Addr
Receiver for Value v1.0([])
Addr returns a pointer value representing the address of v.
It panics if CanAddr() returns false.
Addr is typically used to obtain a pointer to a struct field
or slice element in order to call a method that requires a
pointer receiver.
-
Bool
Receiver for Value v1.0([])
Bool returns v's underlying value.
It panics if v's kind is not Bool.
-
Bytes
Receiver for Value v1.0([])
Bytes returns v's underlying value.
It panics if v's underlying value is not a slice of bytes or
an addressable array of bytes.
-
Call
Receiver for Value v1.0([in])
Call calls the function v with the input arguments in.
For example, if len(in) == 3, v.Call(in) represents the Go call v(in[0], in[1], in[2]).
Call panics if v's Kind is not Func.
It returns the output results as Values.
As in Go, each input argument must be assignable to the
type of the function's corresponding input parameter.
If v is a variadic function, Call creates the variadic slice parameter
itself, copying in the corresponding values.
-
CallSlice
Receiver for Value v1.0([in])
CallSlice calls the variadic function v with the input arguments in,
assigning the slice in[len(in)-1] to v's final variadic argument.
For example, if len(in) == 3, v.CallSlice(in) represents the Go call v(in[0], in[1], in[2]...).
CallSlice panics if v's Kind is not Func or if v is not variadic.
It returns the output results as Values.
As in Go, each input argument must be assignable to the
type of the function's corresponding input parameter.
-
CanAddr
Receiver for Value v1.0([])
CanAddr reports whether the value's address can be obtained with Addr.
Such values are called addressable. A value is addressable if it is
an element of a slice, an element of an addressable array,
a field of an addressable struct, or the result of dereferencing a pointer.
If CanAddr returns false, calling Addr will panic.
-
CanComplex
Receiver for Value v1.0([])
CanComplex reports whether Complex can be used without panicking.
-
CanConvert
Receiver for Value v1.0([t])
CanConvert reports whether the value v can be converted to type t.
If v.CanConvert(t) returns true then v.Convert(t) will not panic.
-
CanFloat
Receiver for Value v1.0([])
CanFloat reports whether Float can be used without panicking.
-
CanInt
Receiver for Value v1.0([])
CanInt reports whether Int can be used without panicking.
-
CanInterface
Receiver for Value v1.0([])
CanInterface reports whether Interface can be used without panicking.
-
CanSet
Receiver for Value v1.0([])
CanSet reports whether the value of v can be changed.
A Value can be changed only if it is addressable and was not
obtained by the use of unexported struct fields.
If CanSet returns false, calling Set or any type-specific
setter (e.g., SetBool, SetInt) will panic.
-
CanUint
Receiver for Value v1.0([])
CanUint reports whether Uint can be used without panicking.
-
Cap
Receiver for Value v1.0([])
Cap returns v's capacity.
It panics if v's Kind is not Array, Chan, Slice or pointer to Array.
-
Close
Receiver for Value v1.0([])
Close closes the channel v.
It panics if v's Kind is not Chan.
-
Convert
Receiver for Value v1.0([t])
Convert returns the value v converted to type t.
If the usual Go conversion rules do not allow conversion
of the value v to type t, or if converting v to type t panics, Convert panics.
-
Elem
Receiver for Value v1.0([])
Elem returns the value that the interface v contains
or that the pointer v points to.
It panics if v's Kind is not Interface or Pointer.
It returns the zero Value if v is nil.
-
Field
Receiver for Value v1.0([i])
Field returns the i'th field of the struct v.
It panics if v's Kind is not Struct or i is out of range.
-
FieldByIndex
Receiver for Value v1.0([index])
FieldByIndex returns the nested field corresponding to index.
It panics if evaluation requires stepping through a nil
pointer or a field that is not a struct.
-
FieldByIndexErr
Receiver for Value v1.0([index])
FieldByIndexErr returns the nested field corresponding to index.
It returns an error if evaluation requires stepping through a nil
pointer, but panics if it must step through a field that
is not a struct.
-
FieldByName
Receiver for Value v1.0([name])
FieldByName returns the struct field with the given name.
It returns the zero Value if no field was found.
It panics if v's Kind is not struct.
-
Float
Receiver for Value v1.0([])
Float returns v's underlying value, as a float64.
It panics if v's Kind is not Float32 or Float64
-
Index
Receiver for Value v1.0([i])
Index returns v's i'th element.
It panics if v's Kind is not Array, Slice, or String or i is out of range.
-
Int
Receiver for Value v1.0([])
Int returns v's underlying value, as an int64.
It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64.
-
Interface
Receiver for Value v1.0([])
Interface returns v's current value as an interface{}.
It is equivalent to:
var i interface{} = (v's underlying value)
It panics if the Value was obtained by accessing
unexported struct fields.
-
InterfaceData
Receiver for Value v1.0([])
InterfaceData returns a pair of unspecified uintptr values.
It panics if v's Kind is not Interface.
In earlier versions of Go, this function returned the interface's
value as a uintptr pair. As of Go 1.4, the implementation of
interface values precludes any defined use of InterfaceData.
Deprecated: The memory representation of interface values is not
compatible with InterfaceData.
-
IsNil
Receiver for Value v1.0([])
IsNil reports whether its argument v is nil. The argument must be
a chan, func, interface, map, pointer, or slice value; if it is
not, IsNil panics. Note that IsNil is not always equivalent to a
regular comparison with nil in Go. For example, if v was created
by calling ValueOf with an uninitialized interface variable i,
i==nil will be true but v.IsNil will panic as v will be the zero
Value.
-
IsValid
Receiver for Value v1.0([])
IsValid reports whether v represents a value.
It returns false if v is the zero Value.
If IsValid returns false, all other methods except String panic.
Most functions and methods never return an invalid Value.
If one does, its documentation states the conditions explicitly.
-
IsZero
Receiver for Value v1.0([])
IsZero reports whether v is the zero value for its type.
It panics if the argument is invalid.
-
Kind
Receiver for Value v1.0([])
Kind returns v's Kind.
If v is the zero Value (IsValid returns false), Kind returns Invalid.
-
Len
Receiver for Value v1.0([])
Len returns v's length.
It panics if v's Kind is not Array, Chan, Map, Slice, String, or pointer to Array.
-
MapIndex
Receiver for Value v1.0([key])
MapIndex returns the value associated with key in the map v.
It panics if v's Kind is not Map.
It returns the zero Value if key is not found in the map or if v represents a nil map.
As in Go, the key's value must be assignable to the map's key type.
-
MapKeys
Receiver for Value v1.0([])
MapKeys returns a slice containing all the keys present in the map,
in unspecified order.
It panics if v's Kind is not Map.
It returns an empty slice if v represents a nil map.
-
MapRange
Receiver for Value v1.0([])
MapRange returns a range iterator for a map.
It panics if v's Kind is not Map.
Call Next to advance the iterator, and Key/Value to access each entry.
Next returns false when the iterator is exhausted.
MapRange follows the same iteration semantics as a range statement.
Example:
iter := reflect.ValueOf(m).MapRange()
for iter.Next() {
k := iter.Key()
v := iter.Value()
...
}
-
Method
Receiver for Value v1.0([i])
Method returns a function value corresponding to v's i'th method.
The arguments to a Call on the returned function should not include
a receiver; the returned function will always use v as the receiver.
Method panics if i is out of range or if v is a nil interface value.
-
MethodByName
Receiver for Value v1.0([name])
MethodByName returns a function value corresponding to the method
of v with the given name.
The arguments to a Call on the returned function should not include
a receiver; the returned function will always use v as the receiver.
It returns the zero Value if no method was found.
-
NumField
Receiver for Value v1.0([])
NumField returns the number of fields in the struct v.
It panics if v's Kind is not Struct.
-
NumMethod
Receiver for Value v1.0([])
NumMethod returns the number of methods in the value's method set.
For a non-interface type, it returns the number of exported methods.
For an interface type, it returns the number of exported and unexported methods.
-
OverflowComplex
Receiver for Value v1.0([x])
OverflowComplex reports whether the complex128 x cannot be represented by v's type.
It panics if v's Kind is not Complex64 or Complex128.
-
OverflowFloat
Receiver for Value v1.0([x])
OverflowFloat reports whether the float64 x cannot be represented by v's type.
It panics if v's Kind is not Float32 or Float64.
-
OverflowInt
Receiver for Value v1.0([x])
OverflowInt reports whether the int64 x cannot be represented by v's type.
It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64.
-
OverflowUint
Receiver for Value v1.0([x])
OverflowUint reports whether the uint64 x cannot be represented by v's type.
It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
-
Pointer
Receiver for Value v1.0([])
Pointer returns v's value as a uintptr.
It returns uintptr instead of unsafe.Pointer so that
code using reflect cannot obtain unsafe.Pointers
without importing the unsafe package explicitly.
It panics if v's Kind is not Chan, Func, Map, Pointer, Slice, or UnsafePointer.
If v's Kind is Func, the returned pointer is an underlying
code pointer, but not necessarily enough to identify a
single function uniquely. The only guarantee is that the
result is zero if and only if v is a nil func Value.
If v's Kind is Slice, the returned pointer is to the first
element of the slice. If the slice is nil the returned value
is 0. If the slice is empty but non-nil the return value is non-zero.
It's preferred to use uintptr(Value.UnsafePointer()) to get the equivalent result.
-
Recv
Receiver for Value v1.0([])
Recv receives and returns a value from the channel v.
It panics if v's Kind is not Chan.
The receive blocks until a value is ready.
The boolean value ok is true if the value x corresponds to a send
on the channel, false if it is a zero value received because the channel is closed.
-
Send
Receiver for Value v1.0([x])
Send sends x on the channel v.
It panics if v's kind is not Chan or if x's type is not the same type as v's element type.
As in Go, x's value must be assignable to the channel's element type.
-
Set
Receiver for Value v1.0([x])
Set assigns x to the value v.
It panics if CanSet returns false.
As in Go, x's value must be assignable to v's type.
-
SetBool
Receiver for Value v1.0([x])
SetBool sets v's underlying value.
It panics if v's Kind is not Bool or if CanSet() is false.
-
SetBytes
Receiver for Value v1.0([x])
SetBytes sets v's underlying value.
It panics if v's underlying value is not a slice of bytes.
-
SetCap
Receiver for Value v1.0([n])
SetCap sets v's capacity to n.
It panics if v's Kind is not Slice or if n is smaller than the length or
greater than the capacity of the slice.
-
SetComplex
Receiver for Value v1.0([x])
SetComplex sets v's underlying value to x.
It panics if v's Kind is not Complex64 or Complex128, or if CanSet() is false.
-
SetFloat
Receiver for Value v1.0([x])
SetFloat sets v's underlying value to x.
It panics if v's Kind is not Float32 or Float64, or if CanSet() is false.
-
SetInt
Receiver for Value v1.0([x])
SetInt sets v's underlying value to x.
It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64, or if CanSet() is false.
-
SetIterKey
Receiver for Value v1.0([iter])
SetIterKey assigns to v the key of iter's current map entry.
It is equivalent to v.Set(iter.Key()), but it avoids allocating a new Value.
As in Go, the key must be assignable to v's type.
-
SetIterValue
Receiver for Value v1.0([iter])
SetIterValue assigns to v the value of iter's current map entry.
It is equivalent to v.Set(iter.Value()), but it avoids allocating a new Value.
As in Go, the value must be assignable to v's type.
-
SetLen
Receiver for Value v1.0([n])
SetLen sets v's length to n.
It panics if v's Kind is not Slice or if n is negative or
greater than the capacity of the slice.
-
SetMapIndex
Receiver for Value v1.0([key elem])
SetMapIndex sets the element associated with key in the map v to elem.
It panics if v's Kind is not Map.
If elem is the zero Value, SetMapIndex deletes the key from the map.
Otherwise if v holds a nil map, SetMapIndex will panic.
As in Go, key's elem must be assignable to the map's key type,
and elem's value must be assignable to the map's elem type.
-
SetPointer
Receiver for Value v1.0([x])
SetPointer sets the unsafe.Pointer value v to x.
It panics if v's Kind is not UnsafePointer.
-
SetString
Receiver for Value v1.0([x])
SetString sets v's underlying value to x.
It panics if v's Kind is not String or if CanSet() is false.
-
SetUint
Receiver for Value v1.0([x])
SetUint sets v's underlying value to x.
It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64, or if CanSet() is false.
-
Slice
Receiver for Value v1.0([i j])
Slice returns v[i:j].
It panics if v's Kind is not Array, Slice or String, or if v is an unaddressable array,
or if the indexes are out of bounds.
-
Slice3
Receiver for Value v1.0([i j k])
Slice3 is the 3-index form of the slice operation: it returns v[i:j:k].
It panics if v's Kind is not Array or Slice, or if v is an unaddressable array,
or if the indexes are out of bounds.
-
String
Receiver for Value v1.0([])
String returns the string v's underlying value, as a string.
String is a special case because of Go's String method convention.
Unlike the other getters, it does not panic if v's Kind is not String.
Instead, it returns a string of the form "<T value>" where T is v's type.
The fmt package treats Values specially. It does not call their String
method implicitly but instead prints the concrete values they hold.
-
TryRecv
Receiver for Value v1.0([])
TryRecv attempts to receive a value from the channel v but will not block.
It panics if v's Kind is not Chan.
If the receive delivers a value, x is the transferred value and ok is true.
If the receive cannot finish without blocking, x is the zero Value and ok is false.
If the channel is closed, x is the zero value for the channel's element type and ok is false.
-
TrySend
Receiver for Value v1.0([x])
TrySend attempts to send x on the channel v but will not block.
It panics if v's Kind is not Chan.
It reports whether the value was sent.
As in Go, x's value must be assignable to the channel's element type.
-
Type
Receiver for Value v1.0([])
Type returns v's type.
-
Uint
Receiver for Value v1.0([])
Uint returns v's underlying value, as a uint64.
It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
-
UnsafeAddr
Receiver for Value v1.0([])
UnsafeAddr returns a pointer to v's data, as a uintptr.
It is for advanced clients that also import the "unsafe" package.
It panics if v is not addressable.
It's preferred to use uintptr(Value.Addr().UnsafePointer()) to get the equivalent result.
-
UnsafePointer
Receiver for Value v1.0([])
UnsafePointer returns v's value as a unsafe.Pointer.
It panics if v's Kind is not Chan, Func, Map, Pointer, Slice, or UnsafePointer.
If v's Kind is Func, the returned pointer is an underlying
code pointer, but not necessarily enough to identify a
single function uniquely. The only guarantee is that the
result is zero if and only if v is a nil func Value.
If v's Kind is Slice, the returned pointer is to the first
element of the slice. If the slice is nil the returned value
is nil. If the slice is empty but non-nil the return value is non-nil.
-
ValueError
Concrete Type v1.0A ValueError occurs when a Value method is invoked on
a Value that does not support it. Such cases are documented
in the description of each method.
-
arrayOfChanDir
Concrete Type v1.0ChanDir represents a channel type's direction.
-
arrayOfKind
Concrete Type v1.0A Kind represents the specific kind of type that a Type represents.
The zero Kind is not a valid kind.
-
arrayOfMapIter
Concrete Type v1.0A MapIter is an iterator for ranging over a map.
See Value.MapRange.
-
arrayOfMethod
Concrete Type v1.0Method represents a single method.
-
arrayOfSelectCase
Concrete Type v1.0A SelectCase describes a single case in a select operation.
The kind of case depends on Dir, the communication direction.
If Dir is SelectDefault, the case represents a default case.
Chan and Send must be zero Values.
If Dir is SelectSend, the case represents a send operation.
Normally Chan's underlying value must be a channel, and Send's underlying value must be
assignable to the channel's element type. As a special case, if Chan is a zero Value,
then the case is ignored, and the field Send will also be ignored and may be either zero
or non-zero.
If Dir is SelectRecv, the case represents a receive operation.
Normally Chan's underlying value must be a channel and Send must be a zero Value.
If Chan is a zero Value, then the case is ignored, but Send must still be a zero Value.
When a receive operation is selected, the received Value is returned by Select.
-
arrayOfSelectDir
Concrete Type v1.0A SelectDir describes the communication direction of a select case.
-
arrayOfSliceHeader
Concrete Type v1.0SliceHeader is the runtime representation of a slice.
It cannot be used safely or portably and its representation may
change in a later release.
Moreover, the Data field is not sufficient to guarantee the data
it references will not be garbage collected, so programs must keep
a separate, correctly typed pointer to the underlying data.
-
arrayOfStringHeader
Concrete Type v1.0StringHeader is the runtime representation of a string.
It cannot be used safely or portably and its representation may
change in a later release.
Moreover, the Data field is not sufficient to guarantee the data
it references will not be garbage collected, so programs must keep
a separate, correctly typed pointer to the underlying data.
-
arrayOfStructField
Concrete Type v1.0A StructField describes a single field in a struct.
-
arrayOfStructTag
Concrete Type v1.0A StructTag is the tag string in a struct field.
By convention, tag strings are a concatenation of
optionally space-separated key:"value" pairs.
Each key is a non-empty string consisting of non-control
characters other than space (U+0020 ' '), quote (U+0022 '"'),
and colon (U+003A ':'). Each value is quoted using U+0022 '"'
characters and Go string literal syntax.
-
arrayOfType
Concrete Type v1.0Type is the representation of a Go type.
Not all methods apply to all kinds of types. Restrictions,
if any, are noted in the documentation for each method.
Use the Kind method to find out the kind of type before
calling kind-specific methods. Calling a method
inappropriate to the kind of type causes a run-time panic.
Type values are comparable, such as with the == operator,
so they can be used as map keys.
Two Type values are equal if they represent identical types.
-
arrayOfValue
Concrete Type v1.0Value is the reflection interface to a Go value.
Not all methods apply to all kinds of values. Restrictions,
if any, are noted in the documentation for each method.
Use the Kind method to find out the kind of value before
calling kind-specific methods. Calling a method
inappropriate to the kind of type causes a run time panic.
The zero Value represents no value.
Its IsValid method returns false, its Kind method returns Invalid,
its String method returns "<invalid Value>", and all other methods panic.
Most functions and methods never return an invalid value.
If one does, its documentation states the conditions explicitly.
A Value can be used concurrently by multiple goroutines provided that
the underlying Go value can be used concurrently for the equivalent
direct operations.
To compare two Values, compare the results of the Interface method.
Using == on two Values does not compare the underlying values
they represent.
-
arrayOfValueError
Concrete Type v1.0A ValueError occurs when a Value method is invoked on
a Value that does not support it. Such cases are documented
in the description of each method.