Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unchecked Cast warning on clone() call.

843793Mar 24 2006 — edited Mar 30 2006
I am new to the Generics scene so I don't understand what the problem is.

Given the following code:
  public static ArrayList<String> removeRecursivePages(ArrayList<String> alPages)
  {
    if (alPages == null)
    {
      return null;
    }
    
    ArrayList<String> alReturn = (ArrayList<String>)alPages.clone();
I get the following warning at the last line:
Rules.java:198: warning: [unchecked] unchecked cast
found   : java.lang.Object
required: java.util.ArrayList<java.lang.String>
                ArrayList<String> alReturn = (ArrayList<String>)alPages.clone();
1 warning
I am compiling using NetBeans 5.0 on JDK 1.5.0_06.

My unit tests come out just fine, so it runs like it should, it just gets annoying every time I compile to see the warning.

Any ideas?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 27 2006
Added on Mar 24 2006
5 comments
979 views