gudii9
asked on
java constructor error
Hi,
I created below Person class with 3 constructors. One with all the fields second one with top 3 fields and third one with bottom three fields.
I am getting below error. can you please advise how to resolve it.
"Duplicate method Person(String, String, String) in type Person"
person.png
I created below Person class with 3 constructors. One with all the fields second one with top 3 fields and third one with bottom three fields.
I am getting below error. can you please advise how to resolve it.
"Duplicate method Person(String, String, String) in type Person"
person.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Looking at your scenario I would solve it by not storing date as a String. I would use a date object, which would then change your signature and make it work.
ASKER
got it. it looks strange if i have got 6 different kinds of string fields, i cannot create one constructor with top 3 fields other second constructor with bottom 3 fields?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Another way to solve this is to switch from a constructor to a factory method - which means a static method which constructs the object for you.
factory method internally calling generica 6 argument costructor right with rest of 3 arguments as null?
public Person(String name, String sex, String joinDate, String ss_number,...) {
}
is it same as factory design pattern approach?
ASKER