Demo:

   

package org.springframework.data.redis.cache;

@FunctionalInterface
public interface CacheKeyPrefix {
    String compute(String var1);

    static CacheKeyPrefix simple() {
        return (name) -> {
            return name + "::";
        };
    }
}

 

   给了接口里面的方法默认实现,可以有多种实现。优点就是,不用实现很多类,也能实现java 多态的特性。

 

posted on 2019-06-01 14:10  蔡苗  阅读(255)  评论(0编辑  收藏  举报