edwardbeckett
1/6/2016 - 2:17 PM

Lambda Scope

Lambda Scope

/**
* javap -c SimpleFunction.class
*/
Compiled from "SimpleFunction.java"
public class com.beckett.lambdas.SimpleFunction {
  static java.util.function.Function<java.lang.Integer, java.lang.Integer> f;

  public com.beckett.lambdas.SimpleFunction();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: getstatic     #2                  // Field f:Ljava/util/function/Function;
       3: iconst_0
       4: invokestatic  #3                  // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       7: invokeinterface #4,  2            // InterfaceMethod java/util/function/Function.apply:(Ljava/lang/Object;)Ljava/lang/Object;
      12: checkcast     #5                  // class java/lang/Integer
      15: invokevirtual #6                  // Method java/lang/Integer.intValue:()I
      18: istore_1
      19: getstatic     #7                  // Field java/lang/System.out:Ljava/io/PrintStream;
      22: iload_1
      23: invokevirtual #8                  // Method java/io/PrintStream.println:(I)V
      26: return

  static {};
    Code:
       0: invokedynamic #9,  0              // InvokeDynamic #0:apply:()Ljava/util/function/Function;
       5: putstatic     #2                  // Field f:Ljava/util/function/Function;
       8: return
}
package com.beckett.lambdas;

import java.util.function.Function;

public class SimpleFunction {

    static Function<Integer, Integer> f = i -> ++i;

    public static void main(String[] args) {
        int i = f.apply(0);
        System.out.println(i);
    }
}