lambda expression - the default method to achieve a variety of excuses

   Demo:

   

package org.springframework.data.redis.cache;

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

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

 

   Interface to the inside of the default implementation of the method, there can be multiple implementations. Advantage is, do not achieve a lot of class, but also to achieve the characteristic java polymorphism.

 

Guess you like

Origin www.cnblogs.com/caibixiang123/p/10959440.html