Self-answering questions about Java (long-term update)

xiaoxiao2021-03-06  82

The following is purely personal opinion, welcome to different sounds: self-friendly: I use the Factory class to manage if you create objects? Self-answer: Because most Java IDE supports operation: Enter class or object, play a point in the back The members and methods available for this class or the object, the factory method is to create objects using factory-class static methods, eliminating the pain of repeating all classes, but also don't have to remember so many class names, big accelerate the program writing.

----- 2004.11.7 02:39

Self-friendly: When do you use Final? Self-Answer: For generic methods and members, it is usually declared as static class members, which is STATIC, which is only one copy at runtime, and does not have to make more objects Call, save system resources; for example, java.lang.math is static; for methods and members who do not want to be modified, declare Final, declare that Final is not subject to subclass modification in the inheritance of the class (ie Not overwriting), the declaration of Final is not modified after the first assignment is assigned. When the Static Final is declared, the static constant is static, and some of the global parameters in programming are usually declared as such, the following example is SystemConstants class declares three states (read only, illegal, can be updated), public class SystemConstants {public static final String STATE_READONLY = "rEADONLY"; public static final String STATE_ILLEGAL = "iLLEGAL"; public static final String STATE_UPDATABLE = "uPDATABLE "} Application: public class documentdao {public string state; // 省 省 ..... public boolean isupdatable () {// Judgment document is not updatable returncture.State.equals (SystemConstants.State_UpData);}} We can reduce the coupling of the system, regardless of the value of State_UPDATABLE.

转载请注明原文地址:https://www.9cbs.com/read-95207.html

New Post(0)