I need to create a list of clients, each of them having a list of jobs. when assigning a List to a client, it is passed by reference and any change made to the list ( clearing it for example ) is also reflected in the client object.
Client client = new Client();
Job job = new Job();
List<Job> jobs = new ArrayList<>();
client.job_run_user_login = "razvan";
job.action = "EMAIL";
jobs.add(job);
client.jobs = jobs;
jobs.clear();
client object before running " jobs.clear(); " line :
client object before running " jobs.clear(); " line :
How can I avoid this?