title: Do I have to cast an Object object to a specific type before using it in my contains and equals method?
body: <p>So I have a Hospital class and inside it, I have a method called remove(Object object) which checks what kind of Object the parameter input is. Then after finding the instance of the object I use my equals method to find the object in the ArrayList to remove. My question is, do I have to cast the object to the specific type before using it?
  Something like this: .........equals((Patient) object))?</p>
  
  <pre><code>public boolean remove(Object object) {
          if(object instanceof Department){
              departments.remove(object);
              return true;
          }
          if(object instanceof Patient){
              for(int i = 0; i &lt; departments.size(); i ++){
                  for(int j = 0; j &lt; departments.size(); j ++) {
                      if (departments.get(i).getPatients().get(j).equals(object)) {
                          departments.get(i).getPatients().remove(j);
                          return true;
                      }
                  }
              }
          }
          if(object instanceof Employee){
              for(int i = 0; i &lt; departments.size(); i ++){
                  for(int j = 0; j &lt; departments.size(); j ++) {
                      if (departments.get(i).getEmployees().get(j).equals(object)) {
                          departments.get(i).getEmployees().remove(j);
                          return true;
                      }
                  }
              }
          }
          return false;
      }
  </code></pre>