What's the best practise when adapting C-style functions which return a true/false to Java?
Here's a simple method to illustrate where the problem lies.
public static boolean fileNameEndsWithExtension( String filename, String fileExtension) {
return filename.endsWith( fileExtension );
}
Note that there's probably a more elegant way of filtering files (feel free to comment on this). Anyway, if filename is a null value, does one:
- Return a false if filename is null? If so, how does one go about distinguishing between the case where filename is
nulland the case where theStringor file name doesn't end with a given file extension? - Change the return type to the wrapper class Boolean which allows a
nullvalue. - Throw an
Exceptionand force the programmer to make sure that anullvalue is never passed to the method? - Use another solution?