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_01.java 694 B

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

No Description

Contributors (1)