About when to use static and tool class knowledge in Java

Source: Internet
Author: User

I. Using the static modifier variable: When shared data is present in an object, the data is statically decorated, and the unique data in the object is defined as non-static in heap memory.

Two. Use static to modify static functions: When there is no access to non-static data (object-specific data) inside the function, it can be defined as static.

Three. Tool classes are designed to encapsulate functionality (in order to encapsulate data), there are no attribute data in the tool class, and only methods that implement various functions are static. To prevent objects in other classes from creating tool classes (tool class objects are meaningless), you can privatize the constructor method of the tool class. Methods that do not need to be opened to the outside of the tool class (the other method calls in these methods feature tool classes) are also privatized.

About when to use static and tool class knowledge in Java

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.