Java Lambda使用记录

lambda与匿名函数的区别

使用案例

1

定义接口

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
/**
 * Strategy interface to filter {@link Entry Entries}.
 */
@FunctionalInterface
interface EntryFilter {

    /**
     * Apply the jar entry filter.
     * @param entry the entry to filter
     * @return {@code true} if the filter matches
     */
    boolean matches(Entry entry);

}

使用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
static final EntryFilter NESTED_ARCHIVE_ENTRY_FILTER = (entry) -> {
    if (entry.isDirectory()) {
        return entry.getName().equals("BOOT-INF/classes/");
    }
    return entry.getName().startsWith("BOOT-INF/lib/");
};

protected boolean isNestedArchive(Archive.Entry entry) {
    return NESTED_ARCHIVE_ENTRY_FILTER.matches(entry);
}

来源:Spring Boot Loader: org.springframework.boot.loader.JarLauncher

Licensed under CC BY-NC-SA 4.0
Built with Hugo
主题 StackJimmy 设计