I have a problem with the object creation in java, I have 3 jar's and every one have a class called "Person", I included those jars files into my project, and I need to define 3 objects Person, the problem is the following:
public class UtilClass {
public static com.jar1.Person definePerson1() {
com.jar1.Person person = new com.jar1.Person();
person.setName(Constant.NAME);
person.setLastName(Constant.LASTNAME);
return person;
}
public static com.jar2.Person definePerson2() {
com.jar2.Person person = new com.jar2.Person();
person.setName(Constant.NAME);
person.setLastName(Constant.LASTNAME);
return person;
}
public static com.jar3.Person definePerson3() {
com.jar3.Person person = new com.jar3.Person();
person.setName(Constant.NAME);
person.setLastName(Constant.LASTNAME);
return person;
}
}
As you can see, the classes are "the same" but the package is different, I have this UtilClass because I defined a method in another class:
public void create() {
com.jar1.Group = new Group(UtilClass.definePerson1()); //Only accept com.jar1.Person
com.jar2.Group = new Group(UtilClass.definePerson2()); //Only accept com.jar2.Person
com.jar3.Group = new Group(UtilClass.definePerson3()); //Only accept com.jar3.Person
}
How I can simplify the class UtilClass
and avoid duplicated code? I can't change my jar files.