Unexpected variable ... is already defined ...

Denis DEBARBIEUX denis.debarbieux at inria.fr
Wed Dec 26 05:39:49 PST 2012


Hi,

In the following example, I embed two functions:
/event -> event.match(event -> "a".equals(event.label))/

I got an error "variable event is already defined".

I am surprise about that. Is-it expected?

If yes, can the inner function (that does the test) use the outer 
parameter event?

Denis
Bonus question: does a short syntax exist to code f.apply (f is function)./

//public class Main {//
//
//    public static void main(String[] args) {//
//        System.out.println("start");//
////
//        // Function<Event, Boolean> test = (event -> 
"a".equals(event.label));//
//        // Function<Event, MatchEvent> matcher = (event -> 
event.match(test));//
////
//        getStream().map(event -> event.match(_event -> 
"a".equals(_event.label))).forEach(System.out::println); // OK//
//        getStream().map(event -> event.match(event -> 
"a".equals(event.label))).forEach(System.out::println); // KO//
////
//        System.out.println("end");//
//    }//
//
//    private static Stream<Event> getStream() {//
//        List<Event> stream = new ArrayList<>();//
//        stream.add(new Event("a"));//
//        stream.add(new Event("b"));//
//         return stream.stream();//
//    }//
//
//}//
//
//class Event {//
////
//    final String label;//
//
//    public Event(String label) {//
//        super();//
//        this.label = label;//
//    }//
////
//    MatchEvent match(Function<Event, Boolean> f) {//
//        // question: short synaxe for apply?//
//        return new MatchEvent(this, f.apply(this));//
//    }//
//
//    @Override//
//    public String toString() {//
//        return "Event [label=" + label + "]";//
//    }//
////
////
////
//}//
//
//class MatchEvent {//
////
//    final Event event;//
//    final boolean match;//
////
//    public MatchEvent(Event event, boolean match) {//
//        super();//
//        this.event = event;//
//        this.match = match;//
//    }//
//
//    @Override//
//    public String toString() {//
//        return "MatchEvent [event=" + event + ", match=" + match + "]";//
//    }//
////
//}/


-- 
Denis Debarbieux
Engineer at INRIA
+33 (0)3.59.35.87.10
Skype: denis.debarbieux



More information about the lambda-dev mailing list