CodePudding user response:
Learn and use the go don't need a very good C language to master.As long as you can distinguish between reference and entity.
Structure it as a Java bean
Not only the OOP concept of Java.
Words Java is not very good, why go,
Originally in Java is easy to fix things now, you will feel not comfortable everywhere.
CodePudding user response:
I understand struct is encapsulation, have the function of the object, want to customize a type, use struct, entity model is done with struct definition,* and & amp; Understand, for example:
Type Dog struct {
}
* Dog Dog representative types of pointer types, the basic types of Dog Dog is * and * said the value of the Dog pointer to its basic value of the Dog type,
Use the address operator & amp; ,& Values for this type of Dog Dog {} {} the pointer value, use value operator *, * d to obtain the basic types of pointer pointing to the d value,
See: https://github.com/stayfoo/stayfoo-hub/blob/master/docs/golang/7, go the pointer. The md
CodePudding user response:
Which Java is easy to get the go go wrong you sayCodePudding user response:
This is not a need to have problems,,,A familiar with Java only and no other language experience to go do not used everywhere,
This nothing controversial, there is no need to return to,
CodePudding user response:
Pointer is the core concept in Go, is one of the main difficulties, when to add "& amp;" , when to add "*", it is easy to confuse,A key point is to distinguish between the definition and difference when using,
* when with "*"?
+ in defining a pointer type in
* when to use "& amp;" ?
+ when the need to convert the entity into a pointer (never define with "& amp;" )
* why the entities into a pointer?
+ if a function's parameters and the return value is a pointer, and you are existing entities (Dog {}), so you'll have to convert to pass parameters or return (& amp; Dog {})
* during a visit to a pointer and a member of the entity has the difference?
+ : no, no matter the Dog is {} entity or a pointer, can use "t legs". This is the Go outstanding design, save a lot of trouble,
* why should define the function parameters and return values as a pointer?
+ to modify parameters in the function values
+ when the return value is null, the cursor can be set to nil, easy, entity should be set to null (null) structure, very troublesome,
+ Go rules, as defined in the structure (struct) method (method), each method has a receiver (receiver), all the methods for a structure, or receptors are all pointer type, or receptors are all entity type, so the general principle is defined as pointer types,
* in addition to defining with "*", and when to use it?
+ when you have a pointer type, but need to return the entity type, need to convert Pointers into entity at this moment, want to use "*", equivalent to "& amp;" The operation,
Another related to the important concept of "reference type (reference type)", in the language, "the map, the channel, slice, interface" is a reference type, "array, struct is a value type (the value type). The reference type similar to Pointers, but not a pointer, the previous can't add" * "to turn it into entities, this part is more complex, to speak through need to write an article, the point I have point out, slowly to understand you,
Other about learning the language, please see my article * * "how fast efficiently learn the language" (https://zhuanlan.zhihu.com/p/77999699) * *, or I/" how to learn Golang?" (https://www.zhihu.com/question/23486344/answer/787113240) for an answer.
CodePudding user response:
Because the company has requirements, written in the go platform is about to begin, then watch online want to also have a lot of online classes, training institutions feel quality is uneven, learned a part, but the feeling is blurredCodePudding user response:
Responsibly say go fun...I also am from Java to go,
Accurately, 2 with now, is not completely to the sort of,
Go this stuff really works, more with more comfortable,
Just don't try to compare it with Java, you will be disappointed.
Go go play, don't habitual use OOP thinking to use it.
Pointer to go everywhere, and many places also request parameter must be a pointer, accustomed to.
Compared with C + + pointer, go pointer is much simple and safe.
CodePudding user response:
From Java to go for half a year, code writing is good, then turned back to Java feel what all is wrongCodePudding user response:
I didn't understand the role of the pointer