[英]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. 更具体地说,我在谈论Java Swing,您将使用lambda表达式添加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. 缺少分号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.