title: Writing a Java library to conditionally handle an input class w/o causing unconditional runtime dependency on that class
body: <p>I have what seems like a tricky Java library task.</p>
  
  <p>I need to write an adapter/helper class for working with <code>JTable</code>s that has some additional functionality if the <code>JTable</code> is a <a href="http://www.jarvana.com/jarvana/view/org/swinglabs/swingx-core/1.6.2/swingx-core-1.6.2-javadoc.jar!/org/jdesktop/swingx/JXTable.html"><code>JXTable</code></a>. But I don't want to add a runtime dependency on swingx-core-1.6.2.jar <em>unless</em> my application actually uses JXTable (in which case it already requires having the SwingX jar file on the classpath)</p>
  
  <p>How can I decouple my code to accomplish this? I don't even know how I can test for JXTable; if I try to use <code>instanceof JXTable</code> as a test, that means my code already has an unconditional runtime dependency on JXTable.</p>
  
  <p>I have written Java libraries before that have "optional" runtime linkage dependencies: if I have this in my library:</p>
  
  <pre><code>package com.foobar.foolib;
  
  // import from whizbang.jar
  import com.whizbang.BloatwareThingy;
  
  public class SuperObject
  {
      /* ... uses a BloatwareThingy ... */
  }
  </code></pre>
  
  <p>and <code>SuperObject</code> is the only class that uses whizbang.jar, then as long as my end application doesn't use <code>SuperObject</code>, then there's no runtime dependency on whizbang.jar; if my end application does want to use <code>SuperObject</code>, then it needs to include whizbang.jar on the classpath. Optional from the standpoint of the application. Works great.</p>
  
  <p><strong>How can I write a method to test for a given JTable being an instance of JXTable, without requiring a dependency on the SwingX jar file if the application only uses JTable?</strong></p>