package info.schleichardt.training.java8.lecture2;

public class P2_FunctionalInterfacesFirstClassMembers {

    //show also Automatic-Resource-Management
}

@@ -45,16 +45,53 @@
 ture2;%0A%0A
+import java.security.MessageDigest;%0A%0A
 public c
@@ -147,48 +147,1567 @@
     
-//show also Automatic-Resource-Management
+@FunctionalInterface%0A    public interface HashFunction %7B%0A        byte%5B%5D hash(final String input) throws Exception;%0A%0A        //return type, works also in classes%0A        static HashFunction ofAlgorithm(final String algorithm) %7B%0A            return input -%3E MessageDigest.getInstance(algorithm).digest(input.getBytes());%0A        %7D%0A    %7D%0A%0A    //member in a class%0A    public static final HashFunction hashFunctionClassMember = input -%3E MessageDigest.getInstance(%22SHA2%22).digest(input.getBytes());%0A    //field%0A    private final HashFunction hashFunctionAsField = input -%3E MessageDigest.getInstance(%22SHA2%22).digest(input.getBytes());%0A%0A    //input parameter%0A    public static byte%5B%5D hashInput(final String input, final HashFunction function) throws Exception %7B%0A        return function.hash(input);%0A    %7D%0A%0A    public static void demoForReturnType() throws Exception %7B%0A        final byte%5B%5D hash1 = HashFunction.ofAlgorithm(%22SHA1%22).hash(%22hello%22);%0A        final byte%5B%5D hash2 = hashInput(%22hello%22, HashFunction.ofAlgorithm(%22SHA1%22));%0A    %7D%0A%0A    //example method that is not at all related to the interface HashFunction%0A    //but still has the same signature of taking a String as input and returning a byte array%0A    public static byte%5B%5D md5(final String input) throws Exception %7B%0A        return MessageDigest.getInstance(%22MD5%22).digest(input.getBytes());%0A    %7D%0A%0A    //method reference%0A    public static void demoForMethodReference() throws Exception %7B%0A        final HashFunction function = P2_FunctionalInterfacesFirstClassMembers::md5;//double colon for method reference%0A    %7D
 %0A%7D%0A

Add description how closures can be first class members.