Why can't @FunctionalInterface be applied to a SAM abstract base class

后端 未结 3 804
星月不相逢
星月不相逢 2020-12-03 14:37

I\'m just starting to learn Camel and the first thing I see is

    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from(         


        
3条回答
  •  孤街浪徒
    2020-12-03 15:17

    In addition to other wonderful answers it should be mentioned that if you really need to create such RouteBuilder objects very often, you can create a helper method like this:

    public static RouteBuilder fromConfigurator(Consumer configurator) {
        return new RouteBuilder() {
            public void configure() {
                configurator.accept(this);
            }
        }
    }
    

    And use it like this:

    context.addRoutes(fromConfigurator(
        rb->rb.from("file:data/inbox?noop=true").to("file:data/outbox")));
    

提交回复
热议问题