mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
add method Value() Value to InterfaceValue.
use Value() in print to print underlying value
from interface.
before:
package main
import "fmt"
func main() {
x := []interface{} {1, "hello", 2.5};
fmt.Println(x[0], x[1], x[2], x);
}
1 hello 2.5 [<non-nil interface> <non-nil interface> <non-nil interface>]
after:
1 hello 2.5 [1 hello 2.5]
R=r
DELTA=44 (22 added, 16 deleted, 6 changed)
OCL=27139
CL=27141
This commit is contained in:
parent
b80fdd1e3b
commit
ac6ebfdea9
4 changed files with 28 additions and 22 deletions
|
|
@ -301,6 +301,16 @@ func TestInterfaceGet(t *testing.T) {
|
|||
assert(v3.Type().String(), "float");
|
||||
}
|
||||
|
||||
func TestInterfaceValue(t *testing.T) {
|
||||
var inter struct { e interface{ } };
|
||||
inter.e = 123.456;
|
||||
v1 := reflect.NewValue(&inter);
|
||||
v2 := v1.(reflect.PtrValue).Sub().(reflect.StructValue).Field(0);
|
||||
assert(v2.Type().String(), "interface { }");
|
||||
v3 := v2.(reflect.InterfaceValue).Value();
|
||||
assert(v3.Type().String(), "float");
|
||||
}
|
||||
|
||||
func TestCopyArray(t *testing.T) {
|
||||
a := []int{ 1, 2, 3, 4, 10, 9, 8, 7 };
|
||||
b := []int{ 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue