title: java: How to make an object to List?
body: <p>I have </p>
  
  <pre><code>List&lt;String&gt; uniqueStrings = stringSet.getElements();
  CompSet&lt;String&gt; stringSet2 = new CompSet&lt;&gt;(uniqueStrings);
  assert stringSet.equals(stringSet2);
  </code></pre>
  
  <p>where uniqueStrings is an List contains "a","b","c".</p>
  
  <p>In class <code>CompSet</code>, I have a equals function to see if the content of object passed into the function is the same as the content of <code>CompSet</code>.</p>
  
  <pre><code>public List&lt;T&gt; getElements() {
      List&lt;T&gt; ele = new ArrayList();
      for (int i =0;i&lt;NUBMER_OF_BUCKETS;i++){
          ele.addAll(storage[i]);
      }
      return ele;
  }
  
  public boolean equals(Object other){
      List&lt;T&gt; x = (List)other;
  
      return x.equals(this.getElements());
  }
  </code></pre>
  
  <p>Yet when I execute the code, the following error occurs:</p>
  
  <blockquote>
    <p>java.lang.ClassCastException: hk.edu.polyu.comp.comp2021.assignment4.CompSet cannot be cast to java.util.List</p>
  </blockquote>
  
  <p>Is there any idea to deal with this?</p>