I have Java
enum
:
public enum ConflictResolutionStrategy {
softResolve,
hardResolve,
}
I want to call it like ConflictResolutionStrategy.hardResolve.apply(case1, case2)
.
Both case1
and case2
objects of the same type. apply
in my case should return nothing.
The basic idea behind this design. Create Strategy
design pattern and resolve conflicts based on the set enum
value.
I cannot find any similar questions on StackOveflow even simple search gives me tons of similar cases which don't resolve my case directly.
I tried The following:
public enum ConflictResolutionStrategy {
softResolve ((CaseType case1, CaseType case2) -> case1.update(case2)),
hardResolve,
}
This version above doesn't compile.
I tried another solution:
public enum ConflictResolutionStrategy {
softResolve,
hardResolve {
public void apply(CaseType case1, CaseType case2) {
case1.update(case2);
}
},
}
The second solution, works okay but requires too much code.