title: Differentiate between BigDecimal for money and BigDecimal for percentages
body: <p>I use <code>BigDecimal</code> throughout my application to handle <strong>money</strong> and <strong>percentages</strong>. But, I need a way to differentiate usage between the two (for the purpose of rendering them, i.e., in a <code>JTable</code>). So, my initial thought was to write two classes which behave exactly like <code>BigDecimal</code> so that I could do <code>instanceof</code> tests on them. So I wrote this code:</p>
  
  <p><strong>DollarValue.java:</strong></p>
  
  <pre><code>import java.math.BigDecimal;
  
  public class DollarValue extends BigDecimal {
  
  }
  </code></pre>
  
  <p><strong>PercentValue.java:</strong></p>
  
  <pre><code>import java.math.BigDecimal;
  
  public class PercentValue extends BigDecimal {
  
  }
  </code></pre>
  
  <p>However, in order to use the constructors (<a href="https://stackoverflow.com/a/1644410/963076">because they cannot be inherited</a>), I you need to manually override every constructor. So, DollarValue.java became a monstrosity:</p>
  
  <pre><code>import java.math.BigDecimal;
  import java.math.BigInteger;
  import java.math.MathContext;
  
  public class DollarValue extends BigDecimal {
  
      public DollarValue(char[] in, int offset, int len) {
          super(in, offset, len);
      }
      public DollarValue(char[] in, int offset, int len, MathContext mc) {
          super(in, offset, len, mc);
      }
      public DollarValue(char[] in) {
          super(in);
      }
      public DollarValue(char[] in, MathContext mc) {
          super(in, mc);
      }
      public DollarValue(String val) {
          super(val);
      }
      public DollarValue(String val, MathContext mc) {
          super(val, mc);
      }
      public DollarValue(double val) {
          super(val);
      }
      public DollarValue(double val, MathContext mc) {
          super(val, mc);
      }
      public DollarValue(BigInteger val) {
          super(val);
      }
      public DollarValue(BigInteger val, MathContext mc) {
          super(val, mc);
      }
      public DollarValue(BigInteger unscaledVal, int scale) {
          super(unscaledVal, scale);
      }
      public DollarValue(BigInteger unscaledVal, int scale, MathContext mc) {
          super(unscaledVal, scale, mc);
      }
      public DollarValue(int val) {
          super(val);
      }
      public DollarValue(int val, MathContext mc) {
          super(val, mc);
      }
      public DollarValue(long val) {
          super(val);
      }
      public DollarValue(long val, MathContext mc) {
          super(val, mc);
      }
  }
  </code></pre>
  
  <p>But what's worse, in implementation, this didn't work because I use the static <code>BigDecimal</code> code a lot. To illustrate:</p>
  
  <pre><code>public static void main(String[] args) {
      DollarValue dollars = DollarValue.ONE;
      DollarValue dollars2 = DollarValue.valueOf(25);
  }
  </code></pre>
  
  <p>throws an error, because <code>DollarValue.ONE</code> is actually a <code>BigDecimal</code>, not a <code>DollarValue</code> and <code>DollarValue#valueOf()</code> returns a <code>BigDecimal</code> too.</p>
  
  <p>So now I'm out of ideas. What is the easiest way to distinguish between two implementations of the same class in the way I'm trying to achieve?? This seems like a simple problem...</p>
  
  <p>Edit: Any solution that allows me to automatically differentiate between the two in a renderer will also work. For instance, I need to feed the values to a <code>JTable</code> and have the <code>JTable</code> display either a dollar sign <code>$</code> for money or a percent sign <code>%</code> for percentages.</p>