I am a newbie in Golang world. I was trying to understand the concept of auto referencing.
My confusion related to the below program? what is the difference between first and the second
- first line in function main
age(20).print()
- second and third line
myAge := age(20)
myAge.print()
Full program below:
package main
import "fmt"
type age uint8
func (a *age) print() {
fmt.Println(a)
}
func main() {
age(20).print() // this line throws error
// however, the below line works properly
myAge := age(20)
myAge.print()
}
Please help to understand the difference between the two approaches. I was in an assumption they both are the same.