title: Class Cast Exception problems with TreeSet
body: <p>Ok, I have this problem to solve: </p>
  
  <p>Create a generic class called <code>VirtualLibrary</code> with a single attribute, <code>totalNumberOfEntries</code>, and with methods which enables the user to set and return an entry. The types of entries are <code>Book</code>, <code>Article</code>, <code>MediaResource</code>, <code>Magazine</code> and <code>Manual</code>. Implement the specific classes for each type of entry. 
  In the <code>main( )</code> method create a <code>SortedSet&lt;VirtualLibrary&gt;</code> variable which maintains all the library entries. Use the methods to add, add multiple, return a specific entry and check if an entry exists in the library. </p>
  
  <pre><code>import java.util.Collections;
  import java.util.Scanner;
  import java.util.SortedSet;
  import java.util.TreeSet;
  
  class VirtualLibrary&lt;T&gt;{
      private int totalNumberOfEntries;
      void setTotalNumberOfEntries(int totalNumberOfEntries) {
          this.totalNumberOfEntries=totalNumberOfEntries;
      }
      int getTotalNumberOfEntries() {
          return this.totalNumberOfEntries;
      }
  }
  class Base{}
  class Book extends Base{
  }
  class Article extends Base{ 
  }
  class MediaResource extends Base{
  }
  class Magazine extends Base{
  }
  class Manual extends Base{
  }
  
  public class P5 {
      static Scanner keyboard = new Scanner(System.in);
      public static void main(String[] args) {
          VirtualLibrary&lt;Book&gt; book = new VirtualLibrary&lt;&gt;();
          SortedSet&lt;VirtualLibrary&gt; lib = new TreeSet&lt;&gt;();
          int totalNumberOfEntries;
          System.out.println("Please insert the total number of entries of the book: ");
          totalNumberOfEntries=keyboard.nextInt();
          book.setTotalNumberOfEntries(totalNumberOfEntries);
          lib.add(book);
          VirtualLibrary&lt;Article&gt; article = new VirtualLibrary&lt;&gt;();
          System.out.println("Please insert the total number of entries of the article: ");
          totalNumberOfEntries=keyboard.nextInt();
          article.setTotalNumberOfEntries(totalNumberOfEntries);
          VirtualLibrary&lt;MediaResource&gt; mediaResource = new VirtualLibrary&lt;&gt;();
          System.out.println("Please insert the total number of entries of the media resource: ");
          totalNumberOfEntries=keyboard.nextInt();
          mediaResource.setTotalNumberOfEntries(totalNumberOfEntries);
          VirtualLibrary&lt;Magazine&gt; magazine = new VirtualLibrary&lt;&gt;();
          System.out.println("Please insert the total number of entries of the magazine: ");
          totalNumberOfEntries=keyboard.nextInt();
          magazine.setTotalNumberOfEntries(totalNumberOfEntries);
          VirtualLibrary&lt;Manual&gt; manual = new VirtualLibrary&lt;&gt;();
          System.out.println("Please insert the total number of entries of the manual: ");
          totalNumberOfEntries=keyboard.nextInt();
          manual.setTotalNumberOfEntries(totalNumberOfEntries);
          Collections.addAll(lib, article,mediaResource,magazine,manual);
          System.out.println(lib.first());
          System.out.println(lib.last());
          System.out.println(lib);
  
      }
  
  }
  </code></pre>
  
  <p>I cant figure it out.</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: class VirtualLibrary cannot be cast to class java.lang.Comparable (VirtualLibrary is in unnamed module of loader 'app'; java.lang.Comparable is in module java.base of loader 'bootstrap')
      at java.base/java.util.TreeMap.compare(TreeMap.java:1291)
      at java.base/java.util.TreeMap.put(TreeMap.java:536)
      at java.base/java.util.TreeSet.add(TreeSet.java:255)
      at P5.main(P5.java:50)
  </code></pre>