title: Comparisons with "Comparable" type variables in java?
body: <p>I'm working on a University assignment, and I have to store elements in an array of the "Comparable" type. Eg: </p>
  
  <pre><code>protected Comparable storage[];
  </code></pre>
  
  <p>The elements that will be stored in this array are going to be either all integers, or all strings, but they're obviously created with the "Comparable" type as opposed to being created as int, or String. </p>
  
  <p>What I'm having problems doing is comparing these values. At any given point, say the array is filled with "Comparable" elements that are actually integers, how can I compare them? I get that I have to use the compareTo() method, but what would the implementation look like? I've looked at the Java document online, and it has simply confused me even more. </p>
  
  <p>Just to summarize, at any given point, the array might have "Comparable" type elements that are actually all integers, or all the elements will be Strings that were also made with the "Comparable" type. There's no mixing and matching of the integer and Strings in the array, it's just one or the other. I want to know how I would make the compareTo() method so that I can easily compare two elements in the array, or any two "Comparable" elements for that matter, and return say a 1, -1, or 0 if one is greater/less than the other</p>
  
  <p>Would appreciate any help. I'm completely lost.</p>