1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 66676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
PackageMainImport("FMT""Reflect""Time")funcMain () {checkcanaddr ()}typeSstruct{XintYstringZint}funcM ()int{return -}varx0 =0funcCheckcanaddr () {//addressable situationV: = reflect. ValueOf (x0) fmt. Printf ("x0:%v \tcan be addressable and set:%t,%t\n", x0, v.canaddr (), V.canset ())//false,falsevarX1 =1v = reflect. Indirect (reflect. ValueOf (x1)) fmt. Printf ("x1:%v \tcan be addressable and set:%t,%t\n", X1, V.canaddr (), V.canset ())//false,falsevarx2 = &X1V = reflect. Indirect (reflect. ValueOf (x2)) fmt. Printf ("X2:%v \tcan be addressable and set:%t,%t\n", x2, V.canaddr (), V.canset ())//true,truevarx3 = time. Now () v = reflect. Indirect (reflect. ValueOf (x3)) FMT. Printf ("X3:%v \tcan be addressable and set:%t,%t\n", X3, V.canaddr (), V.canset ())//false,falsevarx4 = &x3v = reflect. Indirect (reflect. ValueOf (x4)) fmt. Printf ("x4:%v \tcan be addressable and set:%t,%t\n", X4, V.canaddr (), V.canset ())//True,truevarx5 = []int{1,2,3}v = reflect. ValueOf (X5) fmt. Printf ("X5:%v \tcan be addressable and set:%t,%t\n", X5, V.canaddr (), V.canset ())//False,falsevarx6 = []int{1,2,3}v = reflect. ValueOf (X6[0]) FMT. Printf ("x6:%v \tcan be addressable and set:%t,%t\n", X6[0], v.canaddr (), V.canset ())//false,falsevarX7 = []int{1,2,3}v = reflect. ValueOf (X7). Index(0) FMT. Printf ("X7:%v \tcan be addressable and set:%t,%t\n", X7[0], v.canaddr (), V.canset ())//true,truev = reflect. ValueOf (&x7[1]) FMT. Printf ("x7.1:%v \tcan be addressable and set:%t,%t\n", X7[1], v.canaddr (), V.canset ())//true,truevarx8 =[3]int{1,2,3}v = reflect. ValueOf (x8[0]) FMT. Printf ("x8:%v \tcan be addressable and set:%t,%t\n", x8[0], v.canaddr (), V.canset ())//false,false//Https://groups.google.com/forum/#!topic/golang-nuts/RF9zsX82MWwvarX9 =[3]int{1,2,3}v = reflect. Indirect (reflect. ValueOf (x9). Index(0) FMT. Printf ("x9:%v \tcan be addressable and set:%t,%t\n", x9[0], v.canaddr (), V.canset ())//false,falsevarx10 =[3]int{1,2,3}v = reflect. Indirect (reflect. ValueOf (&x10)). Index(0) FMT. Printf ("x9:%v \tcan be addressable and set:%t,%t\n", x10[0], v.canaddr (), V.canset ())//true,truevarx11 = S{}v = reflect. ValueOf (X11) fmt. Printf ("x11:%v \tcan be addressable and set:%t,%t\n", X11, V.canaddr (), V.canset ())//false,falsevarx12 = S{}v = reflect. Indirect (reflect. ValueOf (&x12)) fmt. Printf ("x12:%v \tcan be addressable and set:%t,%t\n", X12, V.canaddr (), V.canset ())//true,truevarX13 = S{}v = reflect. ValueOf (x13). Fieldbyname ("X") FMT. Printf ("x13:%v \tcan be addressable and set:%t,%t\n", X13, V.canaddr (), V.canset ())//false,falsevarx14 = S{}v = reflect. Indirect (reflect. ValueOf (&x14)). Fieldbyname ("X") FMT. Printf ("x14:%v \tcan be addressable and set:%t,%t\n", x14, V.canaddr (), V.canset ())//true,truevarx15 = S{}v = reflect. Indirect (reflect. ValueOf (&x15)). Fieldbyname ("Z") FMT. Printf ("x15:%v \tcan be addressable and set:%t,%t\n", x15, V.canaddr (), V.canset ())//true,falsev = reflect. Indirect (reflect. ValueOf (&s{})) Fmt. Printf ("x15.1:%v \tcan be addressable and set:%t,%t\n", &s{}, V.canaddr (), V.canset ())//true,truevarx16 = Mv = reflect. ValueOf (x16) fmt. Printf ("x16:%p \tcan be addressable and set:%t,%t\n", x16, V.canaddr (), V.canset ())//false,falsevarX17 = Mv = reflect. Indirect (reflect. ValueOf (&x17)) fmt. Printf ("x17:%p \tcan be addressable and set:%t,%t\n", X17, V.canaddr (), V.canset ())//true,truevarx18Interface{} = &X11V = reflect. ValueOf (x18) fmt. Printf ("x18:%v \tcan be addressable and set:%t,%t\n", x18, V.canaddr (), V.canset ())//false,falsevarx19Interface{} = &X11V = reflect. ValueOf (x19). Elem () fmt. Printf ("x19:%v \tcan be addressable and set:%t,%t\n", x19, V.canaddr (), V.canset ())//true,truevarx20 = [...]int{1,2,3}v = reflect. ValueOf ([...]int{1,2,3}) fmt. Printf ("x20:%v \tcan be addressable and set:%t,%t\n", x20, V.canaddr (), V.canset ())//false,false} |