title: Get Class<?> object of anonymous inner class
body: <p>I have a method that needs a Class object which it will construct multiple times:</p>
  
  <pre><code>Class&lt;?&gt; clazz = MyClass.class;
  register(clazz);
  </code></pre>
  
  <p>For some registers, I want to use anonymous classes, but for that I need a <code>Class&lt;?&gt;</code> object from it.</p>
  
  <p>I would use it for registering multiple classes that are very similar, but (in this example) have a different name:</p>
  
  <pre><code>String[] nameList = { "name1", "name2" }; // and a lot more
  for (final String name : nameList) {
      // How would I do the next line?
      // It is supposed to pass the Class&lt;?&gt; for an anonymous class overriding getName()
      register(AnAnonymousClass { 
          @Override
          public String getName() {
              return name;
          });
      }
  }
  </code></pre>
  
  <p><strong>Is there any way of doing this, or does my system have a design flaw? If yes, how would I achieve it then?</strong> By the way, I cannot pass the name via constructor because the constructor has to have the same parameters for all classes (because it will be constructed using reflection).</p>