title: Java Generics : Syntax Explanation
body: <p>I am new to java generics my question is :</p>
  
  <pre><code>public static &lt; E &gt; void printArray( E[] inputArray )
  </code></pre>
  
  <p>In the above statement when the return type of function is void then why we have used <code>E</code> before <code>void</code>? Why this syntax is valid ?</p>
  
  <p>As per theory a method could itself be an return type?</p>
  
  <pre><code>Then suppose E = method_abc then how compiler will manage
  
  public static method_abc void printArray (E[] Array)
  </code></pre>
  
  <p>My reference program was </p>
  
  <pre><code>public class GenericMethodTest
  {
     // generic method printArray                         
     public static &lt; E &gt; void printArray( E[] inputArray )
     {
        // Display array elements              
           for ( E element : inputArray ){        
              System.out.printf( "%s ", element );
           }
           System.out.println();
      }
  
      public static void main( String args[] )
      {
          // Create arrays of Integer, Double and Character
          Integer[] intArray = { 1, 2, 3, 4, 5 };
          Double[] doubleArray = { 1.1, 2.2, 3.3, 4.4 };
          Character[] charArray = { 'H', 'E', 'L', 'L', 'O' };
  
          System.out.println( "Array integerArray contains:" );
          printArray( intArray  ); // pass an Integer array
  
          System.out.println( "\nArray doubleArray contains:" );
          printArray( doubleArray ); // pass a Double array
  
          System.out.println( "\nArray characterArray contains:" );
          printArray( charArray ); // pass a Character array
      } 
  }
  </code></pre>