The difference between the go language and the Java language from the object-oriented point of view

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Go language style

The go language is a compiled static type language that supports concurrent programming and memory garbage collection, with high operational efficiency and a strong scalability (scalable). It is a language design for the software engineering service and enforces the language specification. The go language object-oriented programming is simple and elegant, with no inheritance, hidden this pointer, etc. Its object-oriented is a natural part of the language type system. The entire type of system is seamless through the interface string.

The difference between the go language and the Java language

  1. Type system: There are two sets of completely independent type systems in Java, one set is the value type system, Byte, int, Boolean, char, double another set is Object type System, Integer,hashmap and so on, which are rooted in object type. The value type system expects to be referenced with the object type, and it needs to be boxed. Most types in the go language are value semantics, even including some composite types such as array, struct (struct), and so on, and these types can all have methods. We can add new methods to any type. At the same time the go language can get a reference to an object such as Var b=&a through &

  2. Object passing: The method of an object in Java has a hidden this pointer pass, while the go language object-oriented is simply a syntax to express, there is no hidden this pointer, that is, the method imposed by the target display delivery, is not hidden. In addition, the target is not necessarily a pointer (Java passes a pointer to an object), and if it is a pointer, it may not be named this.
  3. Initialization: There is a default constructor in Java or a user-defined constructor that you do not need in go, and you can customize a normal function.
  4. Accessibility of Members: Java uses keywords such as private,protected,public,package for access control. If you want a symbol to be accessible by another package, you need to define the symbol to start with a capital letter. A symbol that starts with a lowercase letter can only be visited within the package.
  5. Inheritance: Java inheritance is done through the extends keyword and does not support multiple inheritance. The inheritance of the go language is accomplished by an anonymous combination: The base class is defined as a struct, the subclass only needs to place the base class as a member in the definition of the subclass, and the memory layout can be changed by adjusting the position of the base class member.
  6. Interfaces: Interfaces in Java exist as contracts in different components, are mandatory, and classes must declare implementations of an interface that need to inherit from that interface. Even if there are two identical interfaces, but only the names are different, it is only possible to determine whether the class implements the interface by the implementation interface declared by the class, which is called an "intrusive" interface. The non-intrusive interface used in the Go language, where a class only needs to implement all the functions required by the interface, we say that the class implements the interface. The go language can be queried through interfaces (whether the object that the interface points to implements a different interface), the type query, and so on.
  7. Polymorphism: A polymorphic implementation in Java follows a principle: When a Superclass object references a variable that references a subclass object, the type of the referenced object rather than the type of the reference variable determines which member method to call, but the method that is called must be defined in the superclass, that is, the quilt class overrides the method. Polymorphism in Java can be achieved through both inheritance-based and interface-based methods. In the go language, different types of assignments are not allowed, that is, traditional polymorphism is not supported. Interface is an exception and can be assigned with different types as long as a type implements the interface, we can assign the variable of that type to the variable of that interface.

Resources

    • Go on Google: a language design for software engineering purposes

    • Xu Shiwei: Go Language Programming _ object-oriented programming

    • Is go an object-oriented language?

    • Java Improvement Chapter (IV)-----Understanding the polymorphism of Java's three major features

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.