简体   繁体   English

Xtend语法说明

[英]Xtend syntax clarification

I'm trying to 100% understand that the following Xtend syntax means: 我试图100%理解以下Xtend语法的含义:

        myVar.addSelectionListener(
           [MultiSelectionEvent<String> event |
               println(event.toString)
           ]
        )
  • myVar is a com.vaadin.ui.CheckBoxGroup class myVar是com.vaadin.ui.CheckBoxGroup
  • the addSelectionListener assume to receive a com.vaadin.event.selection.MultiSelectionListener interface addSelectionListener假定接收到com.vaadin.event.selection.MultiSelectionListener接口

When implementing the MultiSelectionListenener , one has to implement a selectionChange method which itself takes a MultSelectionEvent object as parameter. 在实现MultiSelectionListenener时 ,必须实现一个selectionChange方法,该方法本身将MultSelectionEvent对象作为参数。

I understand that in my above code, I'm providing the implementation inline in my code. 我了解在上面的代码中,我在代码中提供了内联的实现。 But could anyone provide more details about the syntax? 但是,谁能提供有关语法的更多详细信息?

For example, when do we use [ ] , or | 例如,何时使用[]| |。 in Xtend? 在Xtend中?

That is Xtend's lambda syntax. 这就是Xtend的lambda语法。 So in Java you would write: 因此,在Java中,您将编写:

    myVar.addSelectionListener(
       (MultiSelectionEvent<String> event) -> {
           println(event.toString)
       }
    );

Xtend simply replaces (params)=>{code} with [<params>|<code>] . Xtend只是用[<params>|<code>]代替(params)=>{code}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM