简体   繁体   中英

Can I put an if statement inside a lambda expression in Java?

More specifically, I'm talking about for Java Swing where you would use a lambda expression for adding an ActionListener.

combobox.addActionListener(
    event -> {if (boolean) runMethod()});

I've tried compiling as written, but it didn't work so I'm wondering if such a flow of logic is just not allowed or if I just need to reword a few things.

combobox.addActionListener(
    event -> {if (boolean) runMethod();});

Missing a semicolon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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