You can take Runnableas an argument doTransactionand pass it a lambda expression that updates the person. Here we use Runnableas a functional interface that defines a method that takes no parameters and does not return values.
public void modifySalary(Person person, float salary) {
doTransaction(() -> person.setSalary(salary));
}
public void doTransaction(Runnable action) {
em.getTransaction().begin();
action.run();
em.getTransaction().commit();
}
, Runnable - , , , . , Action,
@FunctionalInterface
interface Action {
void perform();
}
action.perform() doTransaction.