[ 
https://issues.apache.org/jira/browse/FTPSERVER-274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12673824#action_12673824
 ] 

Steve Ulrich commented on FTPSERVER-274:
----------------------------------------

Unlike arrays, a generic definition doesn't allow subclasses.
My problem is a good example, I think:
For convenience reasons I had a method named "internalListFiles" which returned 
an array of type MyFtpFile and the listFiles method just called 
internalListFiles and returned the resulting array:

public FtpFile[] listFiles(){
  return internalListFiles();
}

private MyFtpFile[] internalListFiles(){
....
}

Here, Java realises that MyFtpFile is a subclass of FtpFile and the arrays are 
compatible. The new definition doesn't allow this:

public List<FtpFile> listFiles(){
  return internalListFiles(); //Compiler Error: Incompatible types
}

private List<MyFtpFile> internalListFiles(){
....
}

There are two options I see: First would be to copy the List which is a 
performance drawback, or implement the internalListFiles again, which could 
lead to "copy and waste".

There's just one drawback of "? extends": You can't add any objects to that 
list (because you actually don't know the exact type of this list anymore). 
Which shouldn't be a problem here, since implementations could work with 
covariant return type. (in my case: List<MyFtpFile> listFiles() )
See http://java.sun.com/docs/books/tutorial/java/generics/subtyping.html for a 
more detailed explanation.

> Use Wildcard-Generics in API where possible and plausible
> ---------------------------------------------------------
>
>                 Key: FTPSERVER-274
>                 URL: https://issues.apache.org/jira/browse/FTPSERVER-274
>             Project: FtpServer
>          Issue Type: Improvement
>    Affects Versions: 1.0.0-RC2
>            Reporter: Steve Ulrich
>             Fix For: 1.1
>
>
> Currently the API doesn't make use of wildcard generic types.
> Example FtpFile:
> public abstract List<FtpFile> listFiles();
> The used generic for the return type prevents users from returning lists with 
> their own type (ie: List<MyFtpFile>).
> A change to:
> public abstract List<? extends FtpFile> listFiles();
> Would allow this without any costs (or I just can't see them *g*)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to