Consider a class that comes from the data found in a CSV string and stores some of its fields. It makes sense to create two constructors for this class - one from the original CSV line and one with an explicit variable assignment.
eg.
public MyClass(String csvLine) { String[] fields = StringUtils.split(csvLine, ','); this(fields[3], fields[15], Integer.parseInt([fields[8])); } public MyClass(String name, String address, Integer age) { this.name=name; this.address=address; this.age=age; }
In Java, this is not possible because:
The constructor call should be the first statement in the constructor WhereOnEarth.java
What is the right way to implement this?
source share