From a full object-oriented programming language back to basic
Go is like C with a garbage collector. While it is considered a high-level language, the modern concept of object-oriented programming is thrown out of the window. So-called classes in Go is basically equivalent to struct in C because Go has no real class.
Pointers
In Go, there is a pointer like C or C++. The only cool part is that you don’t need to deal with malloc and free. The garbage collector will handle that.
Variable declaration and type inference
Let’s say you want to declare an integer. In Java, you can do by:
|
|
In Go, it will be:
|
|
or
|
|
Public and private accessor
In Go, if the first character of a variable or method is in lowercase, that variable or method is private. Otherwise
No class in Go.
But you can still have classes in Go with struct.
Here is an example in Java.
|
|
|
|
Here is an example in Go.
|
|
|
|