Reputation: 1316
I have a sequence of function calls like below
int empId = saveEmployee(emp);
int deptId = saveDepartment(dept, empId);
int areaId = saveArea(area, deptId);
1-My question which is better/ best practice in java to return the Object or its required properties,
Employee emp1 = saveEmployee(emp);
Department dept1 = saveDepartment(dept, emp1.getId());
Area area1 = saveArea(area, dept1.getId());
Assuming I only need the Id for my next method.
Upvotes: 1
Views: 81
Reputation: 59960
- My question which is better/ best practice in java to return the Object or its required properties,
I would go with the default result of save
method which return the Object.
<S extends T> S save(S entity);
and it still a choice for you in this point.
- And also, does using primitive types increase performance or memory consumption.
don't use primitive int
instead use Long
for ids, which can hold null
Upvotes: 2
Reputation: 31
As far as i think returning object would be better. As java is object oriented language, best practice is to follow proper access modifiers for each variables with proper getter setter method for each properties.
Upvotes: 0