In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the disadvantages of traditional attribute assignment". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the disadvantages of traditional attribute assignment.
Disadvantages of traditional attribute assignment
The simple Java class is mainly composed of attributes and provides corresponding setter and getter processing methods. At the same time, the biggest feature of the simple Java class is to save the corresponding class attribute content through the object. However, if you use the traditional simple Java class development, then you will also face very troublesome difficulties.
Example: traditional simple Java class operation
Class Emp {private String ename;private String job;public void setEname (String ename) {this.ename = ename;} public void setJob (String job) {this.job = job;} public String getEname () {return ename;} public String getJob () {return job;} / / setter, getter slightly}
In particular, in order to make it easy to understand, the types of the ename and job attributes defined in this Emp class use the String type. According to traditional practice, you should first instantiate the object of the Emp class at this time, and then call the setter method through the instantiated object to set the property content.
Example: traditional call
Public class JavaAPIDemo {public static void main (String [] args) throws Exception {Emp emp=new Emp (); / / developers are more concerned with setting content emp.setEname ("SMITH"); emp.setJob ("CLERK"); / / using System.out.println ("name:" + emp.getEname () + ", position:" + emp.getJob ());}}
During the whole process of instantiating the Emp object and setting up the data, the part of setting the data is the most troublesome. If there are 50 properties in the Emp class, there will be a pile of setter method calls for the entire program. Or further explain that in the actual development, the number of simple Java classes is very large, then if all simple Java classes are involved in attribute assignment, the code in this case will be very repetitive.
According to the traditional intuitive programming method, the problem is that there will be a large number of repeated operations in the code. if you want to solve the repeated operation of the object, then the only solution is the reflection mechanism. The biggest feature of the reflection mechanism is that it can realize the abstract processing of the repeated operations of the same function class according to its own characteristics (Object class direct operation, can directly operate properties or methods).
At this point, I believe you have a deeper understanding of "what are the disadvantages of traditional attribute assignment". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.