How to access return type of a method from another method

Dimitris Boukosis :

I have the following code, where I have as input in the method a double number and 3 array lists of objects:

public static ArrayList<ELPERouteStop> relatedness(double pososto,ArrayList<ELPERouteStop> all_stops, ArrayList<Distance> distances, ArrayList<ELPEVehicleLoaded> vl_list)
{
//do stuff
return destroyedCustomers;
}

I need to call the list destroyedCustomers from another method of the same class. The other class would be:

public void destroySolution(ArrayList<ELPERouteStop> removedCustomers, SolutionCreated sc,ArrayList<shadowVehicle> all_svehicles)
{
//do stuff
}

which I have as input the list of objects I need to access. Is there any way I can have this access? On my main method I have done the following:

LNS lns = new LNS();
lns.destroySolution(LNS_Procedure.relatedness(0.15,all_route_stops, distances, vl_list), sc, all_svehicles);

Is this going to work? Thank you very much in advance!

Paul Benn :

As far as I can see this is a generic case of method a calling method b. Since Java (and most languages) evaluate from the innermost statements to the outerwards ones, it definitely work as you'd expect:

a(b()); // Function composition, produces the result of applying a to the result of b

Java also passes references by value, which means any changes in the callee method (except reassignment) will be visible to the caller. In this case, if b() returns a list and a() adds an element to that list and returns it, whatever calls method a will see the extra element.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=79580&siteId=1