Method-Object pairs in Java

Posted by John Manak on Stack Overflow See other posts from Stack Overflow or by John Manak
Published on 2011-02-15T14:45:46Z Indexed on 2011/02/15 15:25 UTC
Read the original article Hit count: 182

Filed under:

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?

© Stack Overflow or respective owner

Related posts about java