java - regarding object recycling -


I have a question about what is wrong with the code given below:

  ArrayList tempList2 = New ArrayList (); TempList2 = getXYZ (tempList1, tempList2); // method getXYZ getXYZ (ArrayList tempList1, ArrayList tempList2) {Some argues and tempList2 returns objects to TempList2; }  

The code will be executed but it seems to pass the tempList2 for getXYZ method arguments, this object is recycling.

My question is, is the tempList2 recycling Arraylist object right?

My question is, is the tempList2 array object object recycling correct?

I do not quite know what the meaning of "recycling" is? This does not appear to be a case where the application is recycling the object so that it can be avoided by allocating new objects. (The common meaning of "recycling" in Java is.)

If getXYZ is often called with the object with a tempList2 So one way to collect stuff in only one list is the fact that getXYZ a ArrayList opens the possibility that a different ArrayList < / Code> The implementation of the method can be changed to return the example. This is not a problem per copy , but it may be that the caller Does not specify the result of the call properly.

If getXYZ is called once for any given tempList2 object, then it seems a bit weird.

In summary, this code looks a bit messy, and if any getXYZ However, this is not wrong, and there may be some good reasons (or historical reasons) to work in this way, which are not clear in the small part of the code included in your question.

Edit - In response to this comment (written to make it readable)

Actually, the reason for the above code That is, I want to avoid making two array list items for the former: The traditional method will be

  ArrayList tempList2 = new ArrayList (); TempList2 = getXYZ (tempList1); // method getXYZ getXYZ (ArrayList tempList1) {ArrayList tempList = new ArrayList (); // Only once installed / there is some logic and tempList returns the objects in the tempList; }  

The traditional way would be real :

  ArrayList tempList2 = getXYZ (tempList1);  

or

  ArrayList tempList2; // some intermediate lines tempList2 = getXYZ (tempList1); None of these need to create an unnecessary  ArrayList  example of your viewpoint, nor do 2  ArrayList  examples  GetXYZ  method 


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -