You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Expression_Always_True_02.java 678 B

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738
  1. package Expression_Always_True;
  2. import java.util.logging.Logger;
  3. public class Expression_Always_True_02
  4. {
  5. static final Logger log = Logger.getLogger("local-logger");
  6. public void bad()
  7. {
  8. /* FLAW: always evaluates to true */
  9. if(1==1) // bad 表达式永远为true
  10. {
  11. log.info("always prints");
  12. }
  13. }
  14. public void good(int j)
  15. {
  16. boolean tag = true;
  17. if(j == 1){
  18. tag = false;
  19. }
  20. /* FIX: may evaluate to true or false */
  21. if(tag) // good 表达式永远为true
  22. {
  23. log.info("sometimes prints");
  24. }
  25. }
  26. }

No Description

Contributors (1)