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!

List<?> a= new LinkedList<?>();

843793Mar 23 2010 — edited Mar 28 2010
import java.util.*;
public class Test1 {
public static void main (String as[]){

List<?> a= new LinkedList<?>();
a.add("sd");
a.add(1);
a.add(new Integer(3));
a.add(new Object());

Iterator itr =a.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
Object[] b= a.toArray();
for(Object o :b){
System.out.println(o.toString());
}

}
}

I have a question the above code works if the parameterised type is <Object> or without <> , but when i use <?> it results in Error
Exception in thread "main" java.lang.Error: Unresolved compilation problems:

* Cannot instantiate the type LinkedList<?>*

so where can i use this <?> and what it exactly mean ??

Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2010
Added on Mar 23 2010
2 comments
384 views