title: Original class name of a proxy (without manual string manipulation)
body: <p>In Java, how do you get the original class object and/or class name of a Java EE (CDI) proxy?</p>
  
  <p>When using <code>getName()</code> on a proxy instance, the name returned is something like</p>
  
  <pre><code>com.company.employeemgmt.EmployeeManager$Proxy$_$$_WeldSubclass
  </code></pre>
  
  <p>Is there some functionaliy in Java SE (7) or EE (6) that will return either the original, unproxied class instance or its name?</p>
  
  <p>I need:</p>
  
  <pre><code>com.company.employeemgmt.EmployeeManager
  </code></pre>
  
  <p>Of course, I could simply use string manipulation, but I would like to know if such functionality is already Java-(EE)-inbuilt.</p>
  
  <p>I already found <code>java.reflect.Proxy</code>, which I could use to detect proxies:</p>
  
  <pre><code>public static void doSomething( Class&lt;? implements Serializable&gt; managerClass )
  {
      if ( Proxy.isProxyClass( managerClass ) )
      {
          // unproxy how?
          managerClass = managerClass.getUnproxiedClass();
      }
  
      // delegate
      doSomething( managerClass.getName() );
  }
  
  
  public static void doSomething( String prefix )
  {
      // do real work
      ...
  }
  </code></pre>
  
  <p>..., but how would you dereference the original class?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>The trick would be to access <code>MyUtil.doSomething( EmployeeManager.class )</code> (or  <code>MyUtil.doSomething( EmployeeManager.class.getName() )</code>), but I would like to use/pass <code>MyUtil.doSomething( this.getClass() )</code> (or  <code>MyUtil.doSomething( this.getClass().getName() )</code>) from all clients as this code can be copied around without manual changes.</p>