[英]Run methods based on a boolean value
Hello I would like to call a method when a boolean is true. 您好,我想在布尔值为true时调用一个方法。 I tried this: 我尝试了这个:
public void checkboxpress(int i){
assert(day_b_1) ? uncheckbox() : checkbox();
}
but this does not work. 但这不起作用。 Ho can I do that? 我能做到吗? Thanks 谢谢
use an if statement -- don't try to be fancy (KISS -- Keep It Simple, Silly). 使用if语句-不要花哨(亲吻-保持简单,愚蠢)。
if (day_b_1) uncheckbox();
else checkbox();
now if both those methods return a result you can do 现在,如果这两个方法都返回结果,则可以执行
result = day_b_1 ? uncheckbox() : checkbox();
Just simply check if it is true: 只要简单地检查它是否为真:
if(day_b_1)
uncheckbox(); // if day_b_1 is true uncheck
else
checkbox();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.