title: Java - Class type from inside static initialization block
body: <p>Is it possible to get the class type from inside the static initialization block?</p>
  
  <p>This is a simplified version of what I currently have::</p>
  
  <pre><code>class Person extends SuperClass {
  
     String firstName;
  
     static{
        // This function is on the "SuperClass":
        //  I'd for this function to be able to get "Person.class" without me
        //  having to explicitly type it in but "this.class" does not work in 
        //  a static context.
        doSomeReflectionStuff(Person.class);     // IN "SuperClass"
     }
  }
  </code></pre>
  
  <p>This is closer to what I am doing, which is to initialize a data structure that holds information about the object and its annotations, etc...   Perhaps I am using the wrong pattern?</p>
  
  <pre><code>public abstract SuperClass{
     static void doSomeReflectionStuff( Class&lt;?&gt; classType, List&lt;FieldData&gt; fieldDataList ){
        Field[] fields = classType.getDeclaredFields();
        for( Field field : fields ){
           // Initialize fieldDataList
        }
     }
  }
  
  public abstract class Person {
  
     @SomeAnnotation
     String firstName;
  
     // Holds information on each of the fields, I used a Map&lt;String, FieldData&gt;
     //  in my actual implementation to map strings to the field information, but that
     //  seemed a little wordy for this example
     static List&lt;FieldData&gt; fieldDataList = new List&lt;FieldData&gt;();
  
     static{
        // Again, it seems dangerous to have to type in the "Person.class"
        //   (or Address.class, PhoneNumber.class, etc...) every time.
        //   Ideally, I'd liken to eliminate all this code from the Sub class
        //   since now I have to copy and paste it into each Sub class.
        doSomeReflectionStuff(Person.class, fieldDataList);
     }
  }
  </code></pre>
  
  <h2>Edit</h2>
  
  <p>I picked the accepted answer based on what applied best to my problem, however it seems to me that all three of the current answers have their merits.</p>