An example of cloning

xiaoxiao2021-03-06  75

In the general development process, it is often necessary to encounter to remove the data component value object from the database (usually called VO), and then placed in the list set, and transfer the callback. When there is no contact, the program is often necessary to construct a VO instance in the While block, but do not recommend it, and should even be avoided because it will cause the program efficiency. After using Clone technology, the program running efficiency is improved, the following is a common written method, I hope to help everyone.

Vo supporting Clone looks like this:

Package com.xxx;

Import java.util. *;

Public class tempjob imports cloneable {// Declarations it can be subject to Clone

Private string jbnr = null; private string jbdw = null;

Public Object Clone () {Try {Return Super.clone (); // Returns the object after Clone} catch (clonenotsupportedexception e) {system.out.println (e.tostring ());}

Public void setjbnr (String JBnr) {this.jbnr = jbnr;}

Public string getjbnr () {returnjbnr;}

Public void setjbdw (string jbdw) {this.jbdw = jbdw;} public string getjbdw () {returnjbdw;}}

For classes that call VO, like this:

Package com.xxx; import java.sql. *; import java.util. *;

PUBLIC CLASS doJOB {

Private connection con; private resultset r; private arraylist lis = new arraylist ();

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

New Post(0)