Go Language Learning Notes (ii)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
    1. 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. 
    2. The pointer must be used only if you need to modify the object
    3. 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] 
    4. Go language Discards object-oriented concepts such as inheritance, preserving only the combination
    5. Interface type query
      var file1 Writer = ... if file5, OK: = File1. (both. IStream); OK {...} 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.