File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ""Capture of ?"  Compile error, what does it mean?" Watch ""Capture of ?"  Compile error, what does it mean?" New topic
Author

"Capture of ?" Compile error, what does it mean?

Leonardo Crespo
Ranch Hand

Joined: Jul 03, 2005
Posts: 31
Hi, i'm playing with the code to better understand generics.

I tried to compile this:



Which to me is saying "put an ArrayList<Reptile> in a list of unknown. However, i'm getting this compile error:



I am particulary confused by the "capture of ? " message. Can anyone help me understand this error msg?

Thank you. Leonardo.


Leonardo Crespo
Prasanta Chinara
Ranch Hand

Joined: Jul 20, 2005
Posts: 30
Please post the complete code always!

I hope you have the following code (where Reptile is a concrete class):



Here, the static type of the variable li is List<?>. You CAN NOT add anything to a "list of ?" because "?" indicates, we don't know what type it is.

Now the below code would work:


The reasoning is as below:

Prasanta Chinara
Ranch Hand

Joined: Jul 20, 2005
Posts: 30
No idea how that smily came in between ..
I meant:

((List<Reptile> li ) . add(new Reptile());
Leonardo Crespo
Ranch Hand

Joined: Jul 03, 2005
Posts: 31
Got it Prasanta, thank you for answering. I'll also make sure i always post the complete code.

Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "Capture of ?" Compile error, what does it mean?
 
Similar Threads
Generics doubt
Generics not working, compiler still thinks its an Object...
Generic doubt
Generics...please clarify
Generics and ? symbol