title: How to fix "Error: bad operand types for binary operator" in generic method?
body: <p>I am trying to print a specific range of contents in the array. And, I am required using the generic method, but I keep getting these errors, saying bad operand types for binary operator. I want to ask which part I did it wrong, and how can I fix the errors?</p>
  <p>I am using drjava.</p>
  <pre><code>  Integer[ ] integerArray = { 1, 2, 3, 4, 5};
    Double[ ] doubleArray = { 1.1, 2.2, 3.3, 4.4, 5.5 };
    Character[ ] characterArray = { 'H', 'E', 'L', 'L', 'O' };
    Pet[ ] petArray = { new Pet( &quot;Bob&quot;, &quot;Tortoise&quot;, &quot;TSA&quot;, &quot;19950315&quot; ),
                        new Pet( &quot;SweetPea&quot;, &quot;Horse&quot;, &quot;Genie&quot;, &quot;20030214&quot; ),
                        new Pet( &quot;Little&quot;, &quot;Chicken&quot;, &quot;John&quot;, &quot;20190123&quot; ),
                        new Pet( &quot;Dale&quot;, &quot;Chipmunk&quot;, &quot;Sam&quot;, &quot;20090527&quot; ),
                        new Pet( &quot;Smokey&quot;, &quot;Bear&quot;, &quot;USPW&quot;, &quot;19440413&quot; )     };
    
    System.out.printf( &quot;%nRange of integerArray contains:%n&quot; );
    printRange( integerArray, 1, 3); 
    
    System.out.printf( &quot;%nRange of doubleArray contains:%n&quot; );
    printRange( doubleArray, 1, 3 ); 
  
    System.out.printf( &quot;%nRange of characterArray contains:%n&quot; );
    printRange( characterArray, 1, 3 ); 
    
    System.out.printf( &quot;%nRange of petArray contains:%n&quot; );
    printRange( petArray, 1, 3 );
   
  } // end main
  </code></pre>
  <p>// This is the part I'm getting errors at</p>
  <pre><code>public static &lt;T&gt; void printRange( T[ ] inputArray, T start, T stop ){
  
   // display array elements 
   // Error:bad operand type T for unary operator '++' and Error: bad operand types for binar operator
   
      for( T element = start; element &lt; stop; element++ )    
      {
          //Error: bad operand types for binary operator '&gt;='
          first type:  T
          second type: int
          // Error: bad operand types for binary operator '&lt;='
          first type:  T
          second type: T
          //Error: bad operand types for binary operator '&lt;'
          first type:  T
          second type: T
          if( start &lt; stop &amp;&amp; start &gt;= 0 &amp;&amp; stop &lt;= inputArray[inputArray.length-1] )
          {
              System.out.printf( &quot;%s&quot;, element.toString( ) );
          }
     
      } // end enhanced for loop
  
      System.out.println( );
   
  } // end method printRange                                    
  } // end class ArrayMethods
  </code></pre>
  <p>This is the expected output.
  Range of integerArray contains:</p>
  <blockquote>
  <p>2 3</p>
  <p>2.2 3.3</p>
  <p>E L</p>
  </blockquote>