Grokking Advanced Go
Vote

0% completed

​

Reflection Basics

Output:

main.Order {ID:1001 Customer:Ada Items:[{SKU:A-100 Quantity:2 Cents:1250}] Paid:false}

The package fmt contains no code that names Order, and it was written long before this program. Even so, it printed the name of the type, the name of every field, and the value of every field, including the fields of a struct inside a slice.

The function printValue in fmt/print.go does this work with the reflect package. How can a program read a type that it knows nothing about at compile time, when is it allowed to change what it reads, and what does this ability cost?

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content