This is a created article in which the information may have evolved or changed.
Today in order to submit notepad++ highlighted bug, wrote a perverted code.
Bug Address: https://code.google.com/p/go/issues/detail?id=5798
The following is a slightly adjusted code (HTTP://PLAY.GOLANG.ORG/P/RYQ82B7BN2):
package mainimport "fmt"type int bytefunc (p int) Foo() { fmt.Printf("int.Foo: %v\n", p)}func int_Foo(x byte) { f1 := int.Foo f1(int(x)) f2 := int(x).Foo f2()}func main() { int_Foo(32)}
Code output:
int.Foo: 32int.Foo: 32
The main features are as follows:
- The built-in type is redefined
int
and is defined as a type and can be defined as a variable name.
int
method expression for the new type: expressionsint.Foo
int
method value for the new type expressions:int(x).Foo
- cannot be defined recursively as its own type, such as
type int int
. Causes an invalid recursive type error: "Invalid recursive type int".