Go Language Learning Path (episode)-A Question of doubt

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed. Recently, when I wrote the Go Language program, I found a problem. Look at the code first:
Musicplay Project Main.gopackage mainimport ("FMT") type Cat interface {Meow ()}type tabby struct{}func (*tabby) Meow () { Fmt. Println ("Meow")}func Getacat () Cat {var mytabby *tabby = nil//Oops, we forgot to set Mytabby to a real valuereturn mytab By}func Testgetacat () {var ICat catvar tabby *tabby = Nilicat = Tabby//icat = Getacat ()//icat = Nilif ICat = nil {fmt. Println ("Gettest failed!")}} Func Main () {Testgetacat ()}


In calling the Testgetacat () function, my idea is that icat should be nil and then call FMT. Println ("Gettest failed!"). Run the result is no call, this suddenly I feel a bit confused, and then directly add ICAT = nil but is can, so Baidu a bit. Found the article again, address: http://geek.csdn.net/news/detail/102187.

His understanding is this: icat points to a tabby pointer object that points to nil. So ICat is not nil.

Only to be able to understand it for the time being.




Related Article

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.