I am new to java. I have created the following two classes for adding cities (partial code has been shown here):
public class TourManager {
// Holds our cities
private static ArrayList destinationCities = new ArrayList<City>();
// Adds a destination city
public static void addCity(City city) {
destinationCities.add(city);
}
}
public class Tour{
// Holds our tour of cities
private ArrayList tour = new ArrayList<City>();
// Constructs a blank tour
public Tour(){
for (int i = 0; i < TourManager.numberOfCities(); i++) {
tour.add(null);
}
}
public ArrayList getTour(){
return tour;
}
}
Now I have created the following two tour class objects:
Tour currentSolution = new Tour();
Tour newSolution = new Tour(currentSolution.getTour());
I have declared two functions as follows:
void Fuction1(Tour newSolution);
void Fuction2(Tour newSolution);
I want to pass the newsolution object as an argument to the above two functions so that we can manipulate the original object inside both of these functions So, truly speaking, I want to pass the value by reference. Now If I pass it in the following way:
Function1(newsolution);
Function2(newsolution);
Will it change the original object inside both of these functions? If not, then what is the proper way of doing this?