Object comparison method and device, equipment and storage medium

By dynamically generating comparison functions based on annotations in Java object comparison during the compilation stage, the problem of low comparison efficiency of existing Java objects is solved, and a more efficient and tidy object comparison process is achieved.

CN119621024APending Publication Date: 2025-03-14CHINA MERCHANTS BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411569060.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-05
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

The existing Java object comparison method is less efficient, and obtains field information and value information through reflection, resulting in poor performance.

Method used

When the target annotation is detected, a list of elements containing the target annotation is obtained; when the target class does not generate a comparison function, the target method declaration syntax tree of the target class is obtained, and a comparison function is generated based on this to compare object member variables.

Benefits of technology

By dynamically generating templated comparison functions during the compilation stage, the efficiency of Java object comparison and code tidyness are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621024A_ABST
    Figure CN119621024A_ABST
Patent Text Reader

Abstract

The invention discloses an object comparison method and device, equipment and a storage medium, and relates to the technical field of computers.The object comparison method comprises the steps that when a target annotation is detected, an element list containing the target annotation is obtained; when a target class corresponding to the element list does not generate a comparison function, obtaining a target method declaration syntax tree corresponding to the target class; and generating a comparison function for the target class based on the target method declaration syntax tree, wherein the comparison function is used for comparing object member variables. According to the method and the device, the templated comparison function is dynamically generated according to the annotation in the compiling stage, so that compared with an existing mode of performing object comparison by reflecting two to-be-compared objects, the mode can improve the development efficiency and code neatness.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to an object comparison method, apparatus, device and storage medium. Background Art

[0002] Java object comparison is used to compare object member variables, calculate and collect inconsistent field information, and finally output inconsistent information for business function processing. The current implementation method is: through reflection of two objects to be compared, the field information and value information are obtained by reflection, and then the fields are compared one by one, and finally the comparison results are summarized. The disadvantage of this method is that the field information and value information are obtained by reflection, and the performance is poor. Summary of the invention

[0003] The main purpose of the present application is to provide an object comparison method, apparatus, device and storage medium, aiming to solve the technical problem of low efficiency of existing Java object comparison.

[0004] To achieve the above purpose, the present application proposes an object comparison method, which includes:

[0005] When a target annotation is detected, obtaining a list of elements containing the target annotation;

[0006] When the target class corresponding to the element list does not generate a comparison function, obtaining a target method declaration syntax tree corresponding to the target class;

[0007] A comparison function is generated for the target class based on the target method declaration syntax tree, where the comparison function is used to compare object member variables.

[0008] Optionally, the step of generating a comparison function for the target class based on the target method declaration syntax tree comprises:

[0009] Construct a syntax tree lookup table according to the target method declaration syntax tree;

[0010] Traversing the syntax tree lookup table to determine the traversed target syntax tree;

[0011] When the return data of the target syntax tree is a basic data type, an expression syntax tree is constructed for the field corresponding to the target syntax tree, and the step of traversing the syntax tree lookup table is returned;

[0012] A comparison function is generated for the target class according to the expression syntax tree.

[0013] Optionally, after the step of traversing the syntax tree lookup table and determining the traversed target syntax tree, the step further includes:

[0014] When the return data of the target syntax tree is not a basic data type, the target function is called to generate a comparison function corresponding to the target syntax tree.

[0015] Optionally, the step of generating a comparison function corresponding to the target syntax tree includes:

[0016] Generate a task to be executed according to the target syntax tree;

[0017] Submit the task to be executed to the thread pool, and wait for the execution result of the task to be executed;

[0018] A comparison function corresponding to the target syntax tree is determined according to the execution result.

[0019] Optionally, after the step of generating a comparison function for the target class based on the target method declaration syntax tree, the method further includes:

[0020] The comparison function is appended to the class declaration syntax tree corresponding to the target class.

[0021] Optionally, the step of obtaining a target method declaration syntax tree corresponding to the target class includes:

[0022] Obtain the full method declaration syntax tree corresponding to the target class;

[0023] A target method declaration syntax tree that meets a preset comparison function generation condition is determined according to the full method declaration syntax tree.

[0024] Optionally, the preset comparison function generation condition includes a method declaration syntax tree whose name starts with preset letters, whose input parameters are empty and whose return type is not a preset type.

[0025] In addition, to achieve the above purpose, the present application also proposes an object comparison device, the object comparison device comprising:

[0026] A detection module, configured to obtain a list of elements containing a target annotation when a target annotation is detected;

[0027] An acquisition module, used for acquiring a target method declaration syntax tree corresponding to the target class when no comparison function is generated for the target class corresponding to the element list;

[0028] A comparison function generation module is used to generate a comparison function for the target class based on the target method declaration syntax tree, and the comparison function is used to compare object member variables.

[0029] In addition, to achieve the above objectives, the present application also proposes an object comparison device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the object comparison method described above.

[0030] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the object comparison method described above are implemented.

[0031] When the target annotation is detected, the present application obtains an element list containing the target annotation; when the target class corresponding to the element list does not generate a comparison function, the target method declaration syntax tree corresponding to the target class is obtained; a comparison function is generated for the target class based on the target method declaration syntax tree, and the comparison function is used to compare object member variables. Since the present application dynamically generates a templated comparison function based on the annotation during the compilation phase, compared with the existing method of comparing objects by reflecting two objects to be compared, the above method of the present application can improve development efficiency and code neatness. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0033] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0034] Figure 1 A flow chart of the first embodiment of the object comparison method of the present application;

[0035] Figure 2 A schematic diagram of a compilation process provided for the first embodiment of the object comparison method of the present application;

[0036] Figure 3 A schematic diagram of the overall implementation process provided for the first embodiment of the object comparison method of the present application;

[0037] Figure 4 A flow chart of the second embodiment of the object comparison method of the present application;

[0038] Figure 5 A logical diagram of the objective function provided for the second embodiment of the object comparison method of the present application;

[0039] Figure 6 A schematic diagram of generated code provided for the second embodiment of the object comparison method of this application;

[0040] Figure 7 This is a schematic diagram of the module structure of the object comparison device in the embodiment of the present application;

[0041] Figure 8 Schematic diagram of the device structure of the hardware operating environment involved in the object comparison method in the embodiment of the present application.

[0042] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0043] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0044] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0045] The main solution of the embodiment of the present application is: when the target annotation is detected, obtain the element list containing the target annotation; when the target class corresponding to the element list does not generate a comparison function, obtain the target method declaration syntax tree corresponding to the target class; generate a comparison function for the target class based on the target method declaration syntax tree, and the comparison function is used to compare object member variables. Since the templated comparison function is dynamically generated according to the annotation at the compilation stage in the present application, compared with the existing method of comparing objects by reflecting two objects to be compared, the above method of the present application can improve development efficiency and code neatness.

[0046] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, an object comparison device, etc. The following takes the object comparison device as an example to illustrate this embodiment and the following embodiments.

[0047] Based on this, the present application embodiment provides an object comparison method, referring to Figure 1 , Figure 1 A flowchart diagram of the first embodiment of the object comparison method of the present application is provided.

[0048] In this embodiment, the object comparison method includes the following steps:

[0049] Step S10, when a target annotation is detected, obtaining a list of elements containing the target annotation;

[0050] It should be understood that the process of compiling Java source code to generate bytecode can be referred to Figure 2 , Figure 2 A schematic diagram of the compilation process provided for the first embodiment of the object comparison method of the present application; the whole process can be described as follows: the source code undergoes lexical parsing and grammatical parsing to generate an abstract syntax tree, and then the abstract syntax tree is traversed to fill the encountered symbols into the symbol table. Annotation processing: All annotation processors will be processed. If the processor generates new code or class files, the compilation process will restart until no new files are generated. Semantic analysis and bytecode generation: including annotation, data and control flow analysis, syntax sugar removal and node code generation.

[0051] It should be noted that the implementation of this embodiment relies on the annotation processing API (JS R-269) of the Java compiler. By implementing the annotation processor (javax.annotation.processing.AbstractProcessor), the syntax tree is modified to generate an object comparison function, and then the dynamic creation of the object comparison function is completed in the "annotation processing stage" of compiling the bytecode.

[0052] It should be noted that the overall implementation process of this embodiment can refer to Figure 3 , Figure 3 A schematic diagram of the overall implementation process provided for the first embodiment of the object comparison method of the present application. Specifically: First, define the annotation @Dif f. It is used to identify the class that needs to generate the comparison function. Then implement the AbstractProcessor class to complete the code generation. Define the comparison function annotation processor, and inherit AbstractProcessor. Dynamically modify the syntax tree in the function process() to generate a comparison function for the class marked with the annotation @Diff. Then register Abstr actProcessor. Register the comparison function annotation processor in the previous step to resources / META-INF / javax.annotation.processing.AbstractProcessor. And use the SPI mechanism to let the compiler load the processor during the compilation phase and execute the code generation logic. Therefore, it can be seen that process() in this application is the core of generating the object comparison function.

[0053] It should be noted that the target annotation may be a predefined annotation for generating a comparison function. The element list containing the target annotation may be obtained by obtaining an annotation element list (javax.lang.model.element.Element) marked with @Diff (for example, other identifiers may be used in a specific implementation, and @Diff is used in this embodiment) from the compilation context RoundEnvironment, that is, an element list of the target annotation, and the target annotation may be an annotation for generating a comparison function. Since @Diff can only be annotated on a class, the element list is full of class declaration syntax trees that participate in generating the diff() function.

[0054] Step S20, when the target class corresponding to the element list does not generate a comparison function, obtaining a target method declaration syntax tree corresponding to the target class;

[0055] It should be noted that it is necessary to first check each class declaration syntax tree in the element list to determine whether a comparison function already exists. If so, end the process. If there is a target class for which no comparison function has been generated, it is necessary to generate a diff() function for the class. At this time, obtain the target method declaration syntax tree corresponding to the target class. The target method declaration syntax tree can be a getter method declaration syntax tree.

[0056] Furthermore, the step of obtaining the target method declaration syntax tree corresponding to the target class includes:

[0057] Obtain the full method declaration syntax tree corresponding to the target class;

[0058] A target method declaration syntax tree that meets a preset comparison function generation condition is determined according to the full method declaration syntax tree.

[0059] It should be noted that the full method declaration syntax tree is a getter method declaration syntax tree. The preset comparison function generation conditions include a method declaration syntax tree whose name starts with a preset letter, whose input parameter is empty, and whose return type is not a preset type. The preset letter is get, and the preset type is Void.

[0060] In the specific implementation, in order to access the member variable information of the comparison object through the getter method, the full method declaration syntax tree is obtained from the class declaration syntax tree, and only the method declaration syntax tree with a name starting with get, empty input parameters and a return type not of Void is retained.

[0061] Step S30: generating a comparison function for the target class based on the target method declaration syntax tree, wherein the comparison function is used to compare object member variables.

[0062] It should be noted that generating a comparison function for the target class based on the target method declaration syntax tree can be to determine the field information for generating the comparison function according to the target method declaration syntax tree, generate a corresponding field comparison function according to the field information, and then construct the comparison function of the target class according to all the field comparison functions in the target class.

[0063] When the target annotation is detected, this embodiment obtains an element list containing the target annotation; when the target class corresponding to the element list does not generate a comparison function, the target method declaration syntax tree corresponding to the target class is obtained; based on the target method declaration syntax tree, a comparison function is generated for the target class, and the comparison function is used to compare object member variables. Since the templated comparison function is dynamically generated according to the annotation at the compilation stage in this embodiment, compared with the existing method of comparing objects by reflecting two objects to be compared, the above method of this embodiment can improve development efficiency and code neatness.

[0064] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 4 , Figure 4 The flowchart provided in the second embodiment of the object comparison method of the present application, the step S30 further includes the following steps:

[0065] Step S301: constructing a syntax tree lookup table according to the target method declaration syntax tree;

[0066] It should be noted that constructing a syntax tree lookup table according to the target method declaration syntax tree may be to parse the field information carried by the getter method and construct a getter method syntax tree lookup table according to the field name, that is, the syntax tree lookup table.

[0067] Step S302: traverse the syntax tree lookup table to determine the traversed target syntax tree;

[0068] It should be noted that when the return data of the target syntax tree is not a basic data type, the target function is recursively called to generate a comparison function corresponding to the target syntax tree. The target function is a proceed() function.

[0069] In a specific implementation, if the return type is not a basic data type, the field is considered to be an object-type member variable, and process() needs to be called (ie, recursively).

[0070] Step S303: when the return data of the target syntax tree is a basic data type, an expression syntax tree is constructed for the field corresponding to the target syntax tree, and the process returns to the step of traversing the syntax tree lookup table;

[0071] It should be noted that when the return data of the target syntax tree is a basic data type, constructing an expression syntax tree for the field corresponding to the target syntax tree can be a traversal of the getter method syntax tree lookup table. If the return type is not a basic data type, the field is regarded as an object type member variable and process() (i.e., recursion) needs to be called; if the return data is a basic data type, an if expression syntax tree can be constructed for the field, i.e., an expression syntax tree, and its translated semantics are:

[0072] If(!Objects.equals(this.varl,oth.getVarl())){

[0073] Lookup.put(varl.name, new Tuple(varl.name, this.vael, oth.getVarl()))}

[0074] Among them, this.varl: the constructed this access taken out through the identifier expression syntax tree;

[0075] oth.getVarl(): Gets the getter method of the object to be compared by calling the syntax tree;

[0076] Lookup: Map declared by variable declaration syntax tree<String,Tuple> Object, used to store the full comparison results;

[0077] varl.name is the field name retrieved from the variable declaration syntax tree (illustration);

[0078] Tuple: ternary object: used to store single field change details. The constructor parameters have the following meanings: variable name, old value, and new value.

[0079] Step S304: Generate a comparison function for the target class according to the expression syntax tree.

[0080] It should be noted that the step of generating a comparison function for the target class according to the expression syntax tree and counting all expression syntax trees in the target class is to generate a comparison function according to all expression syntax trees in the target class.

[0081] In the specific implementation, please refer to Figure 5 , Figure 5 The objective function logic diagram provided for the second embodiment of the object comparison method of the present application; in this embodiment, process() is the core of generating the object comparison function, and the specific execution process is as follows:

[0082] 1. Get the list of elements annotated with @Diff (javax.lang.model.element.Element) from the compilation context RoundEnvironment. Since @Diff can only be annotated on classes, the element list contains all the class declaration syntax trees involved in generating the diff() function.

[0083] 2. Then check each class declaration syntax tree. If there is a diff() method declaration syntax tree, it means that a diff function has been generated for the class. Otherwise, a diff() function needs to be generated for the class.

[0084] 3. In order to access the member variable information of the comparison object through the getter method, the full method declaration syntax tree is obtained from the class declaration syntax tree, and only the method declaration syntax tree with a name starting with get, empty input parameters, and a return type not of Void is retained. At the same time, the field information carried by the getter is parsed, and the getter method syntax tree lookup table is constructed according to the field name.

[0085] 4. Traverse the syntax tree lookup table of the getter method in step (3). If the return type is not a basic data type, the field is considered to be an object-type member variable and process() needs to be called (i.e., recursively). If the return data is a basic data type, an if expression syntax tree can be constructed for the field. The translated semantics is:

[0086] If(!Objects.equals(this.varl,oth.getVarl())){

[0087] Lookup.put(varl.name, new Tuple(varl.name, this.vael, oth.getVarl()))}

[0088] Among them, this.varl: the constructed this access taken out through the identifier expression syntax tree;

[0089] oth.getVarl(): Gets the getter method of the object to be compared by calling the syntax tree;

[0090] Lookup: Map declared by variable declaration syntax tree<String,Tuple> Object, used to store the full comparison results;

[0091] varl.name is the field name retrieved from the variable declaration syntax tree (illustration);

[0092] Tuple: ternary object: used to store single field change details. The constructor parameters have the following meanings: variable name, old value, and new value.

[0093] 5. Generate the syntax tree of the diff() method body. Create an empty syntax tree for the method body, and append the syntax tree list of the if expression obtained in step (4) to the syntax tree of the method body one by one. At the same time, generate the syntax tree of the return statement, which is used to return the comparison result lookup as an output parameter.

[0094] 6. Generate method definition syntax tree nodes, fill in parameter definition syntax tree, return parameter syntax tree, modifier syntax tree and method body syntax tree, and build a complete diff() function.

[0095] 7. Append the diff() function method definition syntax tree node generated in step (6) to the class declaration syntax tree obtained in step (1).

[0096] 8. After compiling, you can use the annotation processor to dynamically generate the object comparison function diff(). For examples of generated code, please refer to Figure 6 , Figure 6 A schematic diagram of generated code provided for the second embodiment of the object comparison method of this application.

[0097] Furthermore, in order to avoid too many object-type member variables in the above step 4, it is necessary to recursively generate comparison functions for each object-type member variable during compilation, which will affect the compilation speed. In addition, member variables defined in a class are usually not nested too deeply. The scenario with multiple object-type member variables can be optimized to increase the compilation speed. Specifically, the step of generating the comparison function corresponding to the target syntax tree includes:

[0098] Generate a task to be executed according to the target syntax tree;

[0099] Submit the task to be executed to the thread pool, and wait for the execution result of the task to be executed;

[0100] A comparison function corresponding to the target syntax tree is determined according to the execution result.

[0101] In the specific implementation, first encapsulate the member variables of each recursively generated comparison function into a Callable task T. The result returned by this task is the diff() syntax tree in step (6). This diff() syntax tree is only for the current member variable. Then submit task T to the thread pool and insert CountDownLatch as a task waiting barrier. After task T is submitted, wait for the diff() syntax tree of the object-type member variable to be generated. When a task T is executed, immediately append the result of this task to the syntax tree node in step (7). The same is true for other tasks. Finally, wait for all tasks to be executed, that is, complete the generation of diff() syntax trees for all object-type member variables.

[0102] Through the above steps, the generation of diff() syntax trees for object-type member variables can be transformed from a blocking waiting method to a parallel-pipeline method, which can greatly improve the efficiency of syntax tree generation and thus reduce compilation time.

[0103] This embodiment builds a syntax tree lookup table according to the target method declaration syntax tree; traverses the syntax tree lookup table to determine the traversed target syntax tree; when the return data of the target syntax tree is a basic data type, an expression syntax tree is built for the field corresponding to the target syntax tree, and returns to the step of traversing the syntax tree lookup table; generates a comparison function for the target class according to the expression syntax tree. This embodiment dynamically generates templated comparison function code, which improves development efficiency and code neatness.

[0104] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the comparison method of the objects of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0105] This application also provides an object comparison device, please refer to Figure 7 , the object comparison device comprises:

[0106] A detection module 10, configured to obtain a list of elements containing the target annotation when the target annotation is detected;

[0107] An acquisition module 20 is used to acquire a target method declaration syntax tree corresponding to the target class when no comparison function is generated for the target class corresponding to the element list;

[0108] The comparison function generation module 30 is used to generate a comparison function for the target class based on the target method declaration syntax tree, and the comparison function is used to compare object member variables.

[0109] When the target annotation is detected, this embodiment obtains an element list containing the target annotation; when the target class corresponding to the element list does not generate a comparison function, the target method declaration syntax tree corresponding to the target class is obtained; based on the target method declaration syntax tree, a comparison function is generated for the target class, and the comparison function is used to compare object member variables. Since the templated comparison function is dynamically generated according to the annotation at the compilation stage in this embodiment, compared with the existing method of comparing objects by reflecting two objects to be compared, the above method of this embodiment can improve development efficiency and code neatness.

[0110] The object comparison device provided by the present application adopts the object comparison method in the above embodiment, which can solve the technical problem of low efficiency of existing Java object comparison. Compared with the prior art, the beneficial effects of the object comparison device provided by the present application are the same as the beneficial effects of the object comparison method provided by the above embodiment, and other technical features in the object comparison device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0111] The present application provides an object comparison device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the object comparison method in the above-mentioned embodiment 1.

[0112] Reference below Figure 8 , which shows a schematic diagram of the structure of an object comparison device suitable for implementing the embodiment of the present application. The object comparison device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The object comparison device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0113] like Figure 8As shown, the object comparison device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. Various programs and data required for the operation of the object comparison device are also stored in the RAM 1004. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 can allow the object comparison device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an object comparison device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have instead.

[0114] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0115] The object comparison device provided by the present application adopts the object comparison method in the above embodiment, which can solve the technical problem of low efficiency of existing Java object comparison. Compared with the prior art, the beneficial effects of the object comparison device provided by the present application are the same as the beneficial effects of the object comparison method provided by the above embodiment, and other technical features in the object comparison device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0116] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0117] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0118] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the object comparison method in the above-mentioned embodiment.

[0119] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0120] The computer-readable storage medium may be included in the object comparison device; or may exist independently without being assembled into the object comparison device.

[0121] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0122] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0123] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0124] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned object comparison method, and can solve the technical problem of low efficiency of existing Java object comparison. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the object comparison method provided by the above-mentioned embodiment, and will not be repeated here.

[0125] The present application also provides a computer program product, including a computer program, which implements the steps of the object comparison method as described above when executed by a processor.

[0126] The computer program product provided by the present application can solve the technical problem of low efficiency of existing Java object comparison. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the object comparison method provided by the above embodiment, which will not be repeated here.

[0127] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. An object comparison method, characterized in that: The object comparison method comprises the following steps: When a target annotation is detected, obtaining a list of elements containing the target annotation; When the target class corresponding to the element list does not generate a comparison function, obtaining a target method declaration syntax tree corresponding to the target class; A comparison function is generated for the target class based on the target method declaration syntax tree, where the comparison function is used to compare object member variables.

2. The object comparison method according to claim 1, characterized in that: The step of generating a comparison function for the target class based on the target method declaration syntax tree comprises: Construct a syntax tree lookup table according to the target method declaration syntax tree; Traversing the syntax tree lookup table to determine the traversed target syntax tree; When the return data of the target syntax tree is a basic data type, an expression syntax tree is constructed for the field corresponding to the target syntax tree, and the step of traversing the syntax tree lookup table is returned; A comparison function is generated for the target class according to the expression syntax tree.

3. The object comparison method according to claim 2, characterized in that: After the step of traversing the syntax tree lookup table and determining the traversed target syntax tree, the method further includes: When the return data of the target syntax tree is not a basic data type, the target function is recursively called to generate a comparison function corresponding to the target syntax tree.

4. The object comparison method according to claim 3, characterized in that: The step of generating a comparison function corresponding to the target syntax tree comprises: Generate a task to be executed according to the target syntax tree; Submit the task to be executed to the thread pool, and wait for the execution result of the task to be executed; A comparison function corresponding to the target syntax tree is determined according to the execution result.

5. The object comparison method according to any one of claims 1 to 4, characterized in that: After the step of generating a comparison function for the target class based on the target method declaration syntax tree, the method further includes: The comparison function is appended to the class declaration syntax tree corresponding to the target class.

6. The object comparison method according to any one of claims 1 to 4, characterized in that: The step of obtaining the target method declaration syntax tree corresponding to the target class includes: Obtain the full method declaration syntax tree corresponding to the target class; A target method declaration syntax tree that meets a preset comparison function generation condition is determined according to the full method declaration syntax tree.

7. The object comparison method according to claim 6, characterized in that: The preset comparison function generation conditions include a method declaration syntax tree whose name starts with preset letters, whose input parameters are empty and whose return type is not a preset type.

8. An object comparison device, characterized in that: The object comparison device comprises: A detection module, configured to obtain a list of elements containing a target annotation when a target annotation is detected; An acquisition module, used for acquiring a target method declaration syntax tree corresponding to the target class when no comparison function is generated for the target class corresponding to the element list; A comparison function generation module is used to generate a comparison function for the target class based on the target method declaration syntax tree, and the comparison function is used to compare object member variables.

9. An object comparison device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the object comparison method according to any one of claims 1 to 7.

10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the object comparison method according to any one of claims 1 to 7 are implemented.