I spent some time thinking about the various solutions that I visited when I read (I am not very good at Java yet) that using this constructor argument is usually not good practice.
What I'm trying to do is create several objects of the JobGroupMod class and for each JobGroupMod I need to create a certain number of JobMod objects that should be able to refer to the JobGroupMod objects in which they were created.
To accomplish this, I pass "this" to the JobMod constructor, but even if it works, it doesn't feel right.
public class JobGroupMod implements JobGroup { public JobGroupMod(Node n,Set<Job> clusterJobs){ JobMod j=new JobMod(n,this); } }
And now the JobMod class:
public class JobMod implements Job { public JobMod(Node n, JobGroup jg){ setJobGroup(jg); } }
My question is, is there a better way to solve this, or is it my solution in the proposed way?
java constructor this
wallen
source share