title: Cast TreeMap.Submap return: SortedMap, back to TreeMap
body: <p>This seems too tricky for me to be doing this correctly.</p>
  
  <p>I have a <code>TreeMap&lt;Double, (user-defined)Object&gt;</code>, of which I am taking a submap:</p>
  
  <pre><code>        public static reqObj assignObj(reqObj vArg, int startDate, int endDate){
                  reqObj vOut=new reqObj();
  
  
  
                  if (keyAt(vArg.requestObject,startDate)&gt;-1 &amp;&amp; keyAt(vArg.requestObject,endDate)&gt;-1){
                      System.err.println(keyAt(vArg.requestObject,startDate));
                      System.err.println(keyAt(vArg.requestObject,endDate));
  
                      //vOut.requestObject=(TreeMap&lt;Double, dayObj&gt;)
  
                      vArg.requestObject.subMap(
                              keyAt(vArg.requestObject,startDate),
                              keyAt(vArg.requestObject,endDate));
  
                  }
  
                  return vOut;
          } 
  </code></pre>
  
  <p>This works just as expected, but when I go to cast my sorted map back to <code>(TreeMap)</code> I get the following error:</p>
  
  <pre><code>  java.lang.ClassCastException: java.util.TreeMap$SubMap
  </code></pre>
  
  <p>Any help would be great.</p>