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 Generics Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Generics Question" Watch "Generics Question" New topic
Author

Generics Question

Krishna doddi
Greenhorn

Joined: Oct 09, 2006
Posts: 14
public <T> List<T> meth(List<?> type)
{
System.out.println(type); // 1
return new ArrayList<String>(); // 2
}


Line 1 compiles fine.
Line 2 Fails. Reason : List Required

Cant we return a ArrayList where List is required???
I think we can return the subclass right.

Thanks
Siddharth


Sid<br />SCJP 1.5<br />SCBCD (Preparing....)
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2341
Actually the error message from the compiler is



It's not saying that you can't return an ArrayList.

It's saying it expects you to return a List whose elements are the type parameter T.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Generics Question
 
Similar Threads
generics
John Meyers's SCJP mock errata
Genericss
how can I add some stuff in returned List?
Generics doubt