This is a creation in Article, where the information may have evolved or changed.
- Add a method for the type
Package Mainimport ("FMT") type Integer intfunc (A-integer) less (b integer) bool {return a < B}func main () {var a intege r = 1if a.less (2) {FMT. Println ("less true.")}}
Result output: Less true.
- The pointer must be used only if you need to modify the object
- because the inside of the array slice is a pointer to an array, you can change the contents of the array
package mainimport ("FMT") func modifyslice (array []int) { Slice1: = array[1:2]fmt. Println (Slice1) slice1[0] = 4fmt. Println (Slice1) fmt. Println (Array)}func main () {Modifyslice ([]int{1,2,3})} result output: [2][4][1 4 3]
- Go language Discards object-oriented concepts such as inheritance, preserving only the combination
- Interface type query
var file1 Writer = ... if file5, OK: = File1. (both. IStream); OK {...}