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_False_01.java 686 B

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

No Description

Contributors (1)