Tag: class refactoring static class improvement pre some SYS col JSON
No implementation code exists in the interface
The implementation code cannot exist in the interface (although it can be implemented, but if the implementation code is written in the interface, then the interface is bound to a possible change of factors, which results in the implementation is not document and reliable, can be discarded at any time, modified, reconstructed)
Packagejsontest; Public classSalary { Public Static voidMain (string[] args) {b.a.dosomething (); }}Interfacea{ Public voiddosomething ();}Interfaceb{ Public Static FinalA A =NewA () { Public voiddosomething () {System.out.println ("Implementation method in---------interface"); } };}
32. Static variables must first be declared after assigning values
Static variable loading process: The static variable is first loaded when the class is initialized, the JVM will find all the static declarations in the class, and then allocate space, this time just to complete the allocation of the address, has not been assigned, the JVM will be based on static assignment in the class (Static class assignment and static block assignment) in the order of execution. A static variable has only one copy in memory, so the assignment operation changes its value and the address does not change.
33.
Writing high-quality code: 151 recommendations for improving Java Four (classes, objects, methods) 31-51