AW: File.getName() vs. Path.getFileName()

Christian Schlichtherle christian at schlichtherle.de
Thu May 26 11:18:06 PDT 2011


The Javadoc says:

 

@return a path representing the name of the file or directory, or

{@code null} if this path has zero elements

 

This is confusing. How can a path have zero elements? If its "", then it has
one element. Constructing it from null should be possible. So this statement
should probably simply read:

 

@return a path representing the name of the file or directory

 

 

Von: Alan Bateman [mailto:Alan.Bateman at oracle.com] 
Gesendet: Donnerstag, 26. Mai 2011 18:53
An: christian at schlichtherle.de
Cc: nio-discuss at openjdk.java.net; dev at truezip-fsp.java.net
Betreff: Re: File.getName() vs. Path.getFileName()

 

Christian Schlichtherle wrote: 

File file = new File("");

assert file.getName().isEmpty();

assert null == file.toPath().getFileName();

 

That's a very subtle difference. I'ld prefer to return in
Path.getFileName().

Presumably the second assert fails because file.toPath().getFileName() will
return a Path representing the empty path ("") in this case.

-Alan.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-discuss/attachments/20110526/9edcd74f/attachment.html 


More information about the nio-discuss mailing list