I have following class:
public class Owner {
private final Integer id;
private final OwnerType type;
public Owner(Integer iId, Enum eType) {
this.id= iId;
this.lastName = lName;
this.type = eType // how should that work?
}
}
And
public enum OwnerType {
HUMAN,INSTITUTION
}
Which I am calling via:
try {
File file = new File("resources/Owner.txt");
Scanner fileContent = new Scanner(file);
while (fileContent.hasNextLine()) {
String[] person = fileContent.nextLine().split(" ");
this.data.add(new Owner(owner[0],owner[1]));
}
} catch (FileNotFoundException err){
System.out.println(err);
}
Where Owner.txt has a format of:
ID TYPE
Like that:
1 HUMAN
2 INSTITUTION
My question is:
How can I specify the type property of my Owner Object when I am calling the following?
new Owner(owner[0],owner[1])
Enumso that it's not the name of a class in thejava.langpackage? It will make both your code and your question much simpler.AccountOwner) doesn't match the class name (Owner).Enum.valueOfowner. And whatever array it is, it cannot match the parameters of the constructor. Why are you usingEnuminstead ofOwnerTypeanyway?