Jtest logo




Contents  Previous  Next  Index

OPT.UEQ


Avoid unnecessary equality operations with booleans

Description

This rule flags any unnecessary equality operation with booleans.

Comparing a boolean value with true is an identity operation (returns the same boolean value). The advantages of removing this unnecessary comparison with true are:

  1. The code will perform faster (the code generated has about 5 bytecodes less).
  2. The code becomes clearer.

Example

 package OPT;
 
 public class UEQ
 {
     boolean method (String string) {
         return string.endsWith ("a") == true;   // Violation
     }
 }

Repair

 class UEQ_fixed
 {
     boolean method (String string) {
         return string.endsWith ("a");
     }
 }

Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft