August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this section, we are going to see more advanced uses of reflection illustrated in relatively small code blocks using the Go code of advRefl.go.
The advRefl.go program will be presented in five parts – its first part is next:
package main
import (
"fmt"
"os"
"reflect"
)
type t1 int
type t2 int
Note that although both t1 and t2 types are based on int, and therefore are essentially the same type as int, Go treats them as totally different types. Their internal representation after Go parses the code of the program will be main.t1 and main.t2, respectively.
The second code portion from advRefl.go is the following:
type a struct { X int Y float64 Text string } func (a1 a) compareStruct(a2 a) bool { r1 := ...Read now
Unlock full access