I need to sort files by the type of the File. To accomplish the task I first wrote the code below:private static Comparator SortByFileType() {    return Comparator.comparing((File f) -> {        String probeContentType = null;        try {            probeContentType = Files.probeContentType(f.toPath());            if (probeContentType ==null) {                probeContentType = probeContentTypeIsNull;            }        } catch (IOException e) {        }        return probeContentType;    });}Then I needed to perform different sorts, so I decided to make an enum of sorts, but I wasn't able to pass the above code to the enum. I instead rewrote the above code as given below:public enum Sort implements Comparator<File> {/** * Compare files by the name of the File A<->Z * */ByFileName {        },/** * Compare Files by the Type of file */ByFileType {        @Override        public int compare(File f1, File f2) {            String fileType1 = ;            String fileType2 = ;            try {                fileType1 = Files.probeContentType(f1.toPath());                fileType2 = Files.probeContentType(f2.toPath());            } catch (IOException ex) {            }            if (fileType1 == null) {                fileType1 = probeContentTypeIsNull;            }            if (fileType2 == null) {                fileType2 = probeContentTypeIsNull;            }            return fileType1.compareTo(fileType2);        }    }}Now I need to know two things:Can we turn the code passed to the ByFileType enum into a lambda?Can the code passed to the ByFileType be optimized and improved?
Sort files by the type of file
java;sorting;file;enum;lambda