Method-Object pairs in Java
- by John Manak
I'd like to create a list of method-object pairs. Each method is a function returning a boolean. Then:
foreach(pair) {
if method evaluates to true {
do something with the object
}
}
One way of modelling this that I can think of is to have a class Constraint with a method isValid() and for each constraint produce an anonymous class (overriding the isValid() method). I feel like there could be a nicer way. Can you think of any?