Java Lambda 学习指南(二)

Java8学习笔记(二)—— Lambda表达式 Java8学习笔记系列: Java8学习笔记(一)—— 函数式编程的四个基本接口 Java8学习笔记(二)—— Lambda表达式 Java8学习笔记(三)—— Optional类的使用 Java8学习笔记(四) —— Stream流式编程 Java8学习笔记(五)—— 方法引用(::双冒号操作符) 一、什么是Lambda表达式 Lambda是Java8的一个语法糖,... 阅读详情

原文:zh.annas-archive.org/md5/6C9C9AEB5C060CEC246B793E59A880AA

译者:飞龙

协议:CC BY-NC-SA 4.0

附录 A:字节码

等待

package jdk8.byte_code;

class WaitFor {
    static void waitFor(Condition condition) throws    
    InterruptedException {
        while (!condition.isSatisfied())
            Thread.sleep(250);
    }

    static <T> void waitFor(T input, Predicate<T> predicate)
            throws InterruptedException {
        while (!predicate.test(input))
            Thread.sleep(250);
    }
}

示例 1

package jdk8.byte_code;

import static jdk8.byte_code.WaitFor.waitFor;

@SuppressWarnings("all")
public class Example1 {

    // anonymous class
    void example() throws InterruptedException {
        waitFor(new Condition() {
            @Override
            public Boolean isSatisfied() {
                return true;
            }
        });
    }
}
Classfile Example1.class
 Last modified 08-May-2014; size 603 bytes
 MD5 checksum 7365ca98fe204fc9198043cef5d241be
 Compiled from "Example1.java"
public class jdk8.byte_code.Example1
  SourceFile: "Example1.java"
  InnerClasses:
         #2; //class jdk8/byte_code/Example1$1
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
  #1 = Methodref #6.#20 // java/lang/Object." <init>":()V 
  #2 = Class #21 // jdk8/byte_code/Example1$1 
  #3 = Methodref #2.#22 // jdk8/byte_code/Example1$1." <init>":(Ljdk8/byte_code/Example1;)V 
  #4 = Methodref #23.#24 // 
jdk8/byte_code/WaitFor.waitFor:(Ljdk8/byte_code/Condition;)V
 #5 = Class #25 // jdk8/byte_code/Example1
 #6 = Class #26 // java/lang/Object
 #7 = Utf8 InnerClasses
 #8 = Utf8 <init>
 #9 = Utf8 ()V 
 #10 = Utf8 Code
 #11 = Utf8 LineNumberTable
 #12 = Utf8 LocalVariableTable 
 #13 = Utf8 this 
 #14 = Utf8 Ljdk8/byte_code/Example1; 
 #15 = Utf8 example 
 #16 = Utf8 Exceptions 
 #17 = Class #27 // java/lang/InterruptedException 
 #18 = Utf8 SourceFile 
 #19 = Utf8 Example1.java 
 #20 = NameAndType #8:#9 // "":()V 
 #21 = Utf8 jdk8/byte_code/Example1$1 
 #22 = NameAndType #8:#28 // "":(Ljdk8/byte_code/Example1;)V 
 #23 = Class #29 // jdk8/byte_code/WaitFor 
 #24 = NameAndType #30:#31 // waitFor:(Ljdk8/byte_code/Condition;)V 
 #25 = Utf8 jdk8/byte_code/Example1 
 #26 = Utf8 java/lang/Object 
 #27 = Utf8 java/lang/InterruptedException 
 #28 = Utf8 (Ljdk8/byte_code/Example1;)V 
 #29 = Utf8 jdk8/byte_code/WaitFor 
 #30 = Utf8 waitFor 
 #31 = Utf8 (Ljdk8/byte_code/Condition;)V
{ 
 public jdk8.byte_code.Example1();
   descriptor: ()V
   flags: ACC_PUBLIC
   Code:
     stack=1, locals=1, args_size=1
        0: aload_0
        1: invokespecial #1 // Method java/lang/Object."<init>":()V 
        4: return
     LineNumberTable:
       line 6: 0 
     LocalVariableTable:
       Start Length Slot Name Signature
           0     5     0   this Ljdk8/byte_code/Example1;
 void example() throws java.lang.InterruptedException;
    descriptor: ()V
    flags:
    Code:
      stack=3, locals=1, args_size=1
         0: new           #2         // class  
         jdk8/byte_code/Example1$1
         3: dup
         4: aload_0
         5: invokespecial #3        // Method   
 jdk8/byte_code/Example1$1."<init>":(Ljdk8/byte_code/Example1;)V
         8: invokestatic  #4                  // Method jdk8/byte_code/WaitFor.waitFor:(Ljdk8/byte_code/Condition;)V
        11: return
      LineNumberTable:
        line 10: 0
        line 16: 11
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      12     0  this   Ljdk8/byte_code/Example1;
    Exceptions:
      throws java.lang.InterruptedException
}

示例 2

package jdk8.byte_code;

public interface Server {

  Boolean isRunning();

  public class HttpServer implements Server {
    @Override
    public Boolean isRunning() {
      return false;
    }
  }
}

package jdk8.byte_code;

import static jdk8.byte_code.Server.*;
import static jdk8.byte_code.WaitFor.waitFor;

public class Example2 {

    // anonymous class (closure)
    void example() throws InterruptedException {
        Server server = new HttpServer();
        waitFor(new Condition() {
            @Override
            public Boolean isSatisfied() {
                return !server.isRunning();
            }
        });
    }
}
Classfile Example2.class
 Last modified 08-May-2014; size 775 bytes
 MD5 checksum 2becf3c32e2b08abc50465aca7398c4b
 Compiled from "Example2.java"
 public class jdk8.byte_code.Example2
 SourceFile: "Example2.java"
 InnerClasses:
     #4; //class jdk8/byte_code/Example2$1
     public static #27= #2 of #25; //HttpServer=class jdk8/byte_code/Server$HttpServer of class jdk8/byte_code/Server
 minor version: 0
 major version: 52
 flags: ACC_PUBLIC, ACC_SUPER
 Constant pool:
 #1 = Methodref     #8.#24     // java/lang/Object."<init>":()V
 #2 = Class         #26        // jdk8/byte_code/Server$HttpServer
 #3 = Methodref     #2.#24     // jdk8/byte_code/Server$HttpServer."<init>":()V    
 #4 = Class         #28        // jdk8/byte_code/Example2$1 
 #5 = Methodref     #4.#29     // jdk8/byte_code/Example2$1."<init>":(Ljdk8/byte_code/Example2;Ljdk8/byte_code/Server;)V 
 #6 = Methodref     #30.#31    // jdk8/byte_code/WaitFor.waitFor:(Ljdk8/byte_code/Condition;)V 
 #7 = Class         #32        // jdk8/byte_code/Example2
 #8 = Class         #33        // java/lang/Object
 #9 = Utf8          InnerClasses
 #10 = Utf8         <init>
 #11 = Utf8         ()V
 #12 = Utf8         Code 
 #13 = Utf8         LineNumberTable 
 #14 = Utf8         LocalVariableTable 
 #15 = Utf8         this 
 #16 = Utf8         Ljdk8/byte_code/Example2; 
 #17 = Utf8         example 
 #18 = Utf8         server 
 #19 = Utf8         Ljdk8/byte_code/Server; 
 #20 = Utf8         Exceptions 
 #21 = Class        #34          // java/lang/InterruptedException 
 #22 = Utf8         SourceFile
 #23 = Utf8         Example2.java 
 #24 = NameAndType  #10:#11      // "<init>":()V 
 #25 = Class        #35          // jdk8/byte_code/Server 
 #26 = Utf8         jdk8/byte_code/Server$HttpServer 
 #27 = Utf8         HttpServer 
 #28 = Utf8         jdk8/byte_code/Example2$1 
 #29 = NameAndType  #10:#36      // "<init>":(Ljdk8/byte_code/Example2;Ljdk8/byte_code/Server;)V 
 #30 = Class        #37          // jdk8/byte_code/WaitFor 
 #31 = NameAndType  #38:#39      // waitFor:(Ljdk8/byte_code/Condition;)V
 #32 = Utf8         jdk8/byte_code/Example2 
 #33 = Utf8         java/lang/Object
 #34 = Utf8         java/lang/InterruptedException
 #35 = Utf8         jdk8/byte_code/Server
 #36 = Utf8         (Ljdk8/byte_code/Example2;Ljdk8/byte_code/Server;)V
 #37 = Utf8         jdk8/byte_code/WaitFor 
 #38 = Utf8         waitFor 
 #39 = Utf8         (Ljdk8/byte_code/Condition;)V 
{
 public jdk8.byte_code.Example2();
 descriptor: ()V
 flags: ACC_PUBLIC
 Code:
   stack=1, locals=1, args_size=1
     0: aload_0
     1: invokespecial #1        // Method java/lang/Object."<init>":()V
     4: return
     LineNumberTable:
       line 6: 0 
     LocalVariableTable:
     Start Length Slot Name Signature
         0      5    0 this Ljdk8/byte_code/Example2;
 void example() throws java.lang.InterruptedException;
    descriptor: ()V
    flags:
    Code:
      stack=4, locals=2, args_size=1
         0: new           #2   //class jdk8/byte_code/Server$HttpServer
         3: dup
         4: invokespecial #3   //Method jdk8/byte_code/Server$HttpServer."<init>":()V
         7: astore_1
         8: new           #4   // class jdk8/byte_code/Example2$1
        11: dup
        12: aload_0
        13: aload_1
        14: invokespecial #5   // Method jdk8/byte_code/Example2$1."<init>":(Ljdk8/byte_code/Example2;Ljdk8/byte_code/Server;)V
        17: invokestatic  #6   // Method jdk8/byte_code/WaitFor.waitFor:(Ljdk8/byte_code/Condition;)V
        20: return
      LineNumberTable:
        line 10: 0
        line 11: 8
        line 17: 20
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      21     0  this   Ljdk8/byte_code/Example2;
            8      13     1 server   Ljdk8/byte_code/Server;
    Exceptions:
      throws java.lang.InterruptedException
}

示例 3

package jdk8.byte_code;

import static jdk8.byte_code.WaitFor.waitFor;

public class Example3 {
    // simple lambda
    void example() throws InterruptedException {
        waitFor(() -> true);
    }
}
Classfile Example3.class
  Last modified 08-May-2014; size 1155 bytes
  MD5 checksum 22e120de85528efc921bb158588bbaa1
  Compiled from "Example3.java"
public class jdk8.byte_code.Example3
  SourceFile: "Example3.java"
  InnerClasses:
      public static final #50= #49 of #53; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  BootstrapMethods:
    0: #23 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
  Method arguments:
    #24 ()Ljava/lang/Boolean;
    #25 invokestatic jdk8/byte_code/Example3.lambda$example$25:()Ljava/lang/Boolean;
    #24 ()Ljava/lang/Boolean;
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
 #1 = Methodref        #6.#21    // java/lang/Object."<init>":()V
 #2 = InvokeDynamic    #0:#26    // #0:isSatisfied:()Ljdk8/byte_code/Condition; 
 #3 = Methodref        #27.#28   // jdk8/byte_code/WaitFor.waitFor:(Ljdk8/byte_code/Condition;)V 
 #4 = Methodref        #29.#30   // java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean; 
 #5 = Class            #31       // jdk8/byte_code/Example3 
 #6 = Class            #32       // java/lang/Object 
 #7 = Utf8             <init> 
 #8 = Utf8             ()V 
 #9 = Utf8             Code 
 #10 = Utf8            LineNumberTable 
 #11 = Utf8            LocalVariableTable 
 #12 = Utf8            this 
 #13 = Utf8            Ljdk8/byte_code/Example3; 
 #14 = Utf8            example 
 #15 = Utf8            Exceptions 
 #16 = Class           #33       // java/lang/InterruptedException 
 #17 = Utf8            lambda$example$25 
 #18 = Utf8            ()Ljava/lang/Boolean; 
 #19 = Utf8            SourceFile 
 #20 = Utf8            Example3.java 
 #21 = NameAndType     #7:#8     // "<init>":()V 
 #22 = Utf8            BootstrapMethods 
 #23 = MethodHandle    #6:#34    // invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
 #24 = MethodType      #18       // ()Ljava/lang/Boolean;
 #25 = MethodHandle    #6:#35    // invokestatic jdk8/byte_code/Example3.lambda$example$25:()Ljava/lang/Boolean; 
 #26 = NameAndType     #36:#37   // isSatisfied:()Ljdk8/byte_code/Condition;     
 #27 = Class           #38       // jdk8/byte_code/WaitFor 
 #28 = NameAndType     #39:#40   // waitFor:(Ljdk8/byte_code/Condition;)V 
 #29 = Class           #41       // java/lang/Boolean 
 #30 = NameAndType     #42:#43   // valueOf:(Z)Ljava/lang/Boolean; 
 #31 = Utf8            jdk8/byte_code/Example3 
 #32 = Utf8            java/lang/Object
 #33 = Utf8            java/lang/InterruptedException 
 #34 = Methodref       #44.#45   // java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
 #35 = Methodref       #5.#46    // jdk8/byte_code/Example3.lambda$example$25:()Ljava/lang/Boolean; 
 #36 = Utf8            isSatisfied 
 #37 = Utf8            ()Ljdk8/byte_code/Condition;
 #38 = Utf8            jdk8/byte_code/WaitFor
 #39 = Utf8            waitFor
 #40 = Utf8            (Ljdk8/byte_code/Condition;)V 
 #41 = Utf8            java/lang/Boolean 
 #42 = Utf8            valueOf 
 #43 = Utf8            (Z)Ljava/lang/Boolean;
 #44 = Class           #47       // java/lang/invoke/LambdaMetafactory    
 #45 = NameAndType     #48:#52   // metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
 #46 = NameAndType     #17:#18  // lambda$example$25:()Ljava/lang/Boolean;  
 #47 = Utf8            java/lang/invoke/LambdaMetafactory 
 #48 = Utf8            metafactory 
 #49 = Class           #54      // java/lang/invoke/MethodHandles$Lookup 
 #50 = Utf8            Lookup 
 #51 = Utf8            InnerClasses 
 #52 = Utf8 (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
 #53 = Class           #55        // java/lang/invoke/MethodHandles
 #54 = Utf8            java/lang/invoke/MethodHandles$Lookup 
 #55 = Utf8            java/lang/invoke/MethodHandles 
{ 
public jdk8.byte_code.Example3();
 descriptor: ()V
 flags: ACC_PUBLIC
 Code:
  stack=1, locals=1, args_size=1
    0: aload_0
    1: invokespecial #1           // Method java/lang/Object."<init>":()V 
    4: return
 LineNumberTable:
 line 6: 0
 LocalVariableTable:
 Start Length Slot Name Signature
     0      5    0 this Ljdk8/byte_code/Example3;
void example() throws java.lang.InterruptedException;
    descriptor: ()V
    flags:
    Code:
      stack=1, locals=1, args_size=1
         0: invokedynamic #2,  0    // InvokeDynamic #0:isSatisfied:()Ljdk8/byte_code/Condition;
         5: invokestatic  #3       // Method jdk8/byte_code/WaitFor.waitFor:(Ljdk8/byte_code/Condition;)V
         8: return
      LineNumberTable:
        line 10: 0
        line 11: 8
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       9     0  this   Ljdk8/byte_code/Example3;
    Exceptions:
      throws java.lang.InterruptedException
}

示例 4

package jdk8.byte_code;

import static jdk8.byte_code.Server.HttpServer;
import static jdk8.byte_code.WaitFor.waitFor;

public class Example4 {
    // lambda with arguments
    void example() throws InterruptedException {
        waitFor(new HttpServer(), (server) -> server.isRunning());
    }
}
Classfile Example4.class
   Last modified 08-May-2014; size 1414 bytes
   MD5 checksum 7177f97fdf30b0648a09ab98109a479c
   Compiled from "Example4.java"
 public class jdk8.byte_code.Example4
   SourceFile: "Example4.java"
   InnerClasses:
     public static #21= #2 of #29; //HttpServer=class jdk8/byte_code/Server$HttpServer of class jdk8/byte_code/Server 
     public static final #65= #64 of #67; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles 
  BootstrapMethods:
    0: #32 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
 Method arguments:
   #33 (Ljava/lang/Object;)Z
   #34 invokestatic jdk8/byte_code/Example4.lambda$example33 : (*L*
*j*
*d*
*k*8/*b*
*y*
*t*
*e*
[*c*] *o*
*d*
*e*/*S*
*e*
*r*
*v*
*e*
*r*HttpServer;)Z
   #35 (Ljdk8/byte_code/Server$HttpServer;)Z
 minor version: 0
 major version: 52
 flags: ACC_PUBLIC, ACC_SUPER
 Constant pool:
 #1 = Methodref         #9.#28     //java/lang/Object."<init>":()V    
 #2 = Class             #30        //jdk8/byte_code/Server$HttpServer   
 #3 = Methodref         #2.#28     //jdk8/byte_code/Server$HttpServer."<init>":()V 
 #4 = InvokeDynamic     #0:#36     // #0:test:()Ljava/util/function/Predicate;   
 #5 = Methodref         #37.#38    // jdk8/byte_code/WaitFor.waitFor:(Ljava/lang/Object;Ljava/util/function/Predicate;)V 
 #6 = Methodref         #2.#39    // jdk8/byte_code/Server$HttpServer.isRunning:()Ljava/lang/Boolean;
 #7 = Methodref         #40.#41   // java/lang/Boolean.booleanValue:()Z   
 #8 = Class             #42       // jdk8/byte_code/Example4 
 #9 = Class             #43       //java/lang/Object 
 #10 = Utf8             <init>
 #11 = Utf8             ()V 
 #12 = Utf8             Code 
 #13 = Utf8             LineNumberTable 
 #14 = Utf8             LocalVariableTable 
 #15 = Utf8             this 
 #16 = Utf8             Ljdk8/byte_code/Example4; 
 #17 = Utf8             example 
 #18 = Utf8             Exceptions 
 #19 = Class            #44       // java/lang/InterruptedException 
 #20 = Utf8             lambda$example$33 
 #21 = Utf8             HttpServer 
 #22 = Utf8             InnerClasses 
 #23 = Utf8             (Ljdk8/byte_code/Server$HttpServer;)Z 
 #24 = Utf8             server 
 #25 = Utf8             Ljdk8/byte_code/Server$HttpServer; 
#26 = Utf8              SourceFile 
#27 = Utf8              Example4.java 
#28 = NameAndType       #10:#11   // "<init>":()V 
#29 = Class             #45       // jdk8/byte_code/Server 
#30 = Utf8              jdk8/byte_code/Server$HttpServer 
#31 = Utf8              BootstrapMethods 
#32 = MethodHandle      #6:#46    // invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
#33 = MethodType        #47       // (Ljava/lang/Object;)Z 
#34 = MethodHandle      #6:#48    // invokestatic jdk8/byte_code/Example4.lambda$example33 : (*L*
*j*
*d*
*k*8/*b*
*y*
*t*
*e*
[*c*] *o*
*d*
*e*/*S*
*e*
*r*
*v*
*e*
*r*HttpServer;)Z 
#35 = MethodType        #23       // (Ljdk8/byte_code/Server$HttpServer;)Z 
#36 = NameAndType       #49:#50   // test:()Ljava/util/function/Predicate; 
#37 = Class             #51       // jdk8/byte_code/WaitFor 
#38 = NameAndType       #52:#53   // waitFor:(Ljava/lang/Object;Ljava/util/function/Predicate;)V 
#39 = NameAndType       #54:#55   // isRunning:()Ljava/lang/Boolean; 
#40 = Class             #56       // java/lang/Boolean 
#41 = NameAndType       #57:#58   // booleanValue:()Z 
#42 = Utf8              jdk8/byte_code/Example4 
#43 = Utf8              java/lang/Object 
#44 = Utf8              java/lang/InterruptedException 
#45 = Utf8              jdk8/byte_code/Server 
#46 = Methodref         #59.#60   // java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
#47 = Utf8              (Ljava/lang/Object;)Z 
#48 = Methodref         #8.#61    // jdk8/byte_code/Example4.lambda$example33 : (*L*
*j*
*d*
*k*8/*b*
*y*
*t*
*e*
[*c*] *o*
*d*
*e*/*S*
*e*
*r*
*v*
*e*
*r*HttpServer;)Z 
#49 = Utf8              test 
#50 = Utf8              ()Ljava/util/function/Predicate; 
#51 = Utf8              jdk8/byte_code/WaitFor 
#52 = Utf8              waitFor 
#53 = Utf8           (Ljava/lang/Object;Ljava/util/function/Predicate;)V 
#54 = Utf8              isRunning 
#55 = Utf8              ()Ljava/lang/Boolean; 
#56 = Utf8              java/lang/Boolean 
#57 = Utf8              booleanValue 
#58 = Utf8              ()Z 
#59 = Class             #62       // java/lang/invoke/LambdaMetafactory 
#60 = NameAndType #63:#66 // metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
#61 = NameAndType       #20:#23   // lambda$example33 : (*L*
*j*
*d*
*k*8/*b*
*y*
*t*
*e*
[*c*] *o*
*d*
*e*/*S*
*e*
*r*
*v*
*e*
*r*HttpServer;)Z 
#62 = Utf8              java/lang/invoke/LambdaMetafactory 
#63 = Utf8              metafactory 
#64 = Class             #68       // java/lang/invoke/MethodHandles$Lookup 
#65 = Utf8              Lookup 
#66 = Utf8 (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
#67 = Class             #69       // java/lang/invoke/MethodHandles 
#68 = Utf8              java/lang/invoke/MethodHandles$Lookup 
#69 = Utf8              java/lang/invoke/MethodHandles
{
 public jdk8.byte_code.Example4();
 descriptor: ()V
 flags: ACC_PUBLIC
 Code: stack=1, locals=1, args_size=1
 0: aload_0 1:
 invokespecial #1                 // Method java/lang/Object."":()V 
 4: return
 LineNumberTable:
 line 9: 0
 LocalVariableTable:
 Start Length Slot Name Signature
     0      5    0 this Ljdk8/byte_code/Example4;
 void example() throws java.lang.InterruptedException;
   descriptor: ()V
   flags:
   Code:
     stack=2, locals=1, args_size=1
         0: new           #2      //class jdk8/byte_code/Server$HttpServer
         3: dup
         4: invokespecial #3      //Method jdk8/byte_code/Server$HttpServer."<init>":()V
         7: invokedynamic #4,  0  //InvokeDynamic #0:test:()Ljava/util/function/Predicate;
        12: invokestatic  #5      // Method jdk8/byte_code/WaitFor.waitFor:(Ljava/lang/Object;Ljava/util/function/Predicate;)V
        15: return
      LineNumberTable:
        line 13: 0
        line 15: 15
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      16     0  this   Ljdk8/byte_code/Example4;
    Exceptions:
      throws java.lang.InterruptedException
}

示例 4(使用方法引用)

package jdk8.byte_code;

import static jdk8.byte_code.Server.HttpServer;
import static jdk8.byte_code.WaitFor.waitFor;

@SuppressWarnings("all")
public class Example4_method_reference {
    // lambda with method reference
    void example() throws InterruptedException {
        waitFor(new HttpServer(), HttpServer::isRunning);
    }

}
Classfile Example4_method_reference.class
  Last modified 08-May-2014; size 1271 bytes
  MD5 checksum f8aef942361f29ef599adfec7a594948
  Compiled from "Example4_method_reference.java"
public class jdk8.byte_code.Example4_method_reference
 SourceFile: "Example4_method_reference.java"
 InnerClasses:
   public static #23= #2 of #21; //HttpServer=class jdk8/byte_code/Server$HttpServer of class jdk8/byte_code/Server 
   public static final #52= #51 of #56; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles 
  BootstrapMethods:
    0: #26 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
    Method arguments:
       #27 (Ljava/lang/Object;)Z 
       #28 invokevirtual jdk8/byte_code/Server$HttpServer.isRunning:()Ljava/lang/Boolean;
       #29 (Ljdk8/byte_code/Server$HttpServer;)Z
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
 #1 = Methodref       #7.#20         //java/lang/Object."<init>":()V    
 #2 = Class           #22            //jdk8/byte_code/Server$HttpServer    
 #3 = Methodref       #2.#20         //  jdk8/byte_code/Server$HttpServer."<init>":()V 
 #4 = InvokeDynamic   #0:#30         // #0:test:()Ljava/util/function/Predicate; 
 #5 = Methodref       #31.#32        // jdk8/byte_code/WaitFor.waitFor:(Ljava/lang/Object;Ljava/util/function/Predicate;)V 
 #6 = Class           #33            // jdk8/byte_code/Example4_method_reference 
 #7 = Class           #34            // java/lang/Object 
 #8 = Utf8            <init> 
 #9 = Utf8            ()V 
 #10 = Utf8           Code 
 #11 = Utf8           LineNumberTable 
 #12 = Utf8           LocalVariableTable 
 #13 = Utf8           this  
 #14 = Utf8           Ljdk8/byte_code/Example4_method_reference; 
 #15 = Utf8           example 
 #16 = Utf8           Exceptions 
 #17 = Class          #35            // java/lang/InterruptedException   
 #18 = Utf8           SourceFile
 #19 = Utf8           Example4_method_reference.java
 #20 = NameAndType    #8:#9         // "<init>":()V
 #21 = Class          #36           // jdk8/byte_code/Server 
 #22 = Utf8           jdk8/byte_code/Server$HttpServer 
 #23 = Utf8           HttpServer 
 #24 = Utf8           InnerClasses 
 #25 = Utf8           BootstrapMethods 
 #26 = MethodHandle   #6:#37        // invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
#27 = MethodType      #38           // (Ljava/lang/Object;)Z 
#28 = MethodHandle    #5:#39        // invokevirtual jdk8/byte_code/Server$HttpServer.isRunning:()Ljava/lang/Boolean;
#29 = MethodType      #40           // (Ljdk8/byte_code/Server$HttpServer;)Z 
#30 = NameAndType     #41:#42       // test:()Ljava/util/function/Predicate; 
#31 = Class           #43           //jdk8/byte_code/WaitFor 
#32 = NameAndType     #44:#45       // waitFor:(Ljava/lang/Object;Ljava/util/function/Predicate;)V 
#33 = Utf8            jdk8/byte_code/Example4_method_reference
#34 = Utf8            java/lang/Object 
#35 = Utf8            java/lang/InterruptedException 
#36 = Utf8            jdk8/byte_code/Server 
#37 = Methodref       #46.#47       // java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
#38 = Utf8            (Ljava/lang/Object;)Z 
#39 = Methodref       #2.#48        // jdk8/byte_code/Server$HttpServer.isRunning:()Ljava/lang/Boolean; 
#40 = Utf8            (Ljdk8/byte_code/Server$HttpServer;)Z
#41 = Utf8            test 
#42 = Utf8            ()Ljava/util/function/Predicate;
#43 = Utf8            jdk8/byte_code/WaitFor 
#44 = Utf8            waitFor 
#45 = Utf8           (Ljava/lang/Object;Ljava/util/function/Predicate;)V 
#46 = Class           #49           // java/lang/invoke/LambdaMetafactory 
#47 = NameAndType     #50:#53       // metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
#48 = NameAndType     #54:#55       // isRunning:()Ljava/lang/Boolean; #49 = Utf8            java/lang/invoke/LambdaMetafactory 
#50 = Utf8            metafactory 
#51 = Class           #57           // java/lang/invoke/MethodHandles$Lookup 
#52 = Utf8            Lookup 
#53 = Utf8 (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
#54 = Utf8            isRunning 
#55 = Utf8            ()Ljava/lang/Boolean;
#56 = Class           #58 // java/lang/invoke/MethodHandles 
#57 = Utf8            java/lang/invoke/MethodHandles$Lookup
#58 = Utf8            java/lang/invoke/MethodHandles 
{
 public jdk8.byte_code.Example4_method_reference();
   descriptor: ()V 
   flags: ACC_PUBLIC
   Code:
     stack=1, locals=1, args_size=1
      0: aload_0
      1: invokespecial #1           // Method java/lang/Object."":()V    
      4: return 
LineNumberTable:
 line 7: 0 
LocalVariableTable:
 Start Length Slot Name Signature
     0      5    0 this Ljdk8/byte_code/Example4_method_reference;  void example() throws java.lang.InterruptedException;
    descriptor: ()V
    flags:
    Code:
      stack=2, locals=1, args_size=1
         0: new           #2                  // class jdk8/byte_code/Server$HttpServer
         3: dup
         4: invokespecial #3                  // Method jdk8/byte_code/Server$HttpServer."<init>":()V
         7: invokedynamic #4,  0              // InvokeDynamic #0:test:()Ljava/util/function/Predicate;
        12: invokestatic  #5                  // Method jdk8/byte_code/WaitFor.waitFor:(Ljava/lang/Object;Ljava/util/function/Predicate;)V
        15: return
      LineNumberTable:
        line 11: 0
        line 12: 15
      LocalVariableTable:
      Start Length Slot Name Signature
      0     16     0    this Ljdk8/byte_code/Example4_method_reference;  
    Exceptions:
      throws java.lang.InterruptedException
  }

示例 5

package jdk8.byte_code;

import static jdk8.byte_code.Server.*;
import static jdk8.byte_code.WaitFor.waitFor;

public class Example5 {

    // closure
    void example() throws InterruptedException {
        Server server = new HttpServer();
        waitFor(() -> !server.isRunning());
    }
}
Classfile Example5.class
 Last modified 08-May-2014; size 1470 bytes
 MD5 checksum 7dd0f577d4b4b903500264acf9649c30
 Compiled from "Example5.java"
 public class jdk8.byte_code.Example5
 SourceFile: "Example5.java"
 InnerClasses:
   public static #31= #2 of #29; //HttpServer=class jdk8/byte_code/Server$HttpServer of class jdk8/byte_code/Server
   public static final #68= #67 of #70; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
 BootstrapMethods:
   0: #34 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
 Method arguments:
 #35 ()Ljava/lang/Boolean; // <-- signature and return type of the SAM method to be implemented by the lambda
 #36 invokestatic jdk8/byte_code/Example5.lambda$example$35:(Ljdk8/byte_code/Server;)Ljava/lang/Boolean;
 #35 ()Ljava/lang/Boolean; // <-- signature and return type to be enforced at invocation time
 minor version: 0
 major version: 52
 flags: ACC_PUBLIC, ACC_SUPER
 Constant pool:
 #1 = Methodref            #10.#28   //java/lang/Object."<init>":()V
 #2 = Class                #30       //jdk8/byte_code/Server$HttpServer   
 #3 = Methodref            #2.#28    // jdk8/byte_code/Server$HttpServer."<init>":()V
 #4 = InvokeDynamic        #0:#37    // #0:isSatisfied:(Ljdk8/byte_code/Server;)Ljdk8/byte_code/Condition;
 #5 = Methodref            #38.#39   // jdk8/byte_code/WaitFor.waitFor:(Ljdk8/byte_code/Condition;)V 
 #6 = InterfaceMethodref   #29.#40   // jdk8/byte_code/Server.isRunning:()Ljava/lang/Boolean;
 #7 = Methodref            #41.#42   // java/lang/Boolean.booleanValue:()Z 
 #8 = Methodref            #41.#43   // java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean; 
 #9 = Class                #44       // jdk8/byte_code/Example5 
 #10 = Class               #45       // java/lang/Object
 #11 = Utf8                <init> 
 #12 = Utf8                ()V 
 #13 = Utf8                Code 
 #14 = Utf8                LineNumberTable 
 #15 = Utf8                LocalVariableTable 
 #16 = Utf8                this 
 #17 = Utf8                Ljdk8/byte_code/Example5; 
 #18 = Utf8                example 
 #19 = Utf8                server 
 #20 = Utf8                Ljdk8/byte_code/Server; 
 #21 = Utf8                Exceptions 
 #22 = Class               #46 // java/lang/InterruptedException 
 #23 = Utf8                lambda$example$35 
 #24 = Utf8                (Ljdk8/byte_code/Server;)Ljava/lang/Boolean;   
 #25 = Utf8                StackMapTable
 #26 = Utf8                SourceFile
 #27 = Utf8                Example5.java
 #28 = NameAndType         #11:#12   // "<init>":()V 
 #29 = Class               #47       // jdk8/byte_code/Server 
 #30 = Utf8                jdk8/byte_code/Server$HttpServer
 #31 = Utf8                HttpServer 
 #32 = Utf8                InnerClasses 
 #33 = Utf8                BootstrapMethods
 #34 = MethodHandle        #6:#48    // invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
 #35 = MethodType          #49       // ()Ljava/lang/Boolean; 
 #36 = MethodHandle        #6:#50    // invokestatic jdk8/byte_code/Example5.lambda$example$35:(Ljdk8/byte_code/Server;)Ljava/lang/Boolean; 
 #37 = NameAndType         #51:#52   // isSatisfied:(Ljdk8/byte_code/Server;)Ljdk8/byte_code/Condition; 
 #38 = Class              #53        // jdk8/byte_code/WaitFor 
 #39 = NameAndType        #54:#55    // waitFor:(Ljdk8/byte_code/Condition;)V 
 #40 = NameAndType        #56:#49    // isRunning:()Ljava/lang/Boolean; 
 #41 = Class              #57        // java/lang/Boolean 
 #42 = NameAndType        #58:#59    // booleanValue:()Z 
 #43 = NameAndType        #60:#61    // valueOf:(Z)Ljava/lang/Boolean; 
 #44 = Utf8               jdk8/byte_code/Example5 
 #45 = Utf8               java/lang/Object 
 #46 = Utf8               java/lang/InterruptedException 
 #47 = Utf8               jdk8/byte_code/Server 
 #48 = Methodref          #62.#63    // java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
 #49 = Utf8               ()Ljava/lang/Boolean;
 #50 = Methodref          #9.#64     // jdk8/byte_code/Example5.lambda$example$35:(Ljdk8/byte_code/Server;)Ljava/lang/Boolean;
 #51 = Utf8               isSatisfied
 #52 = Utf8          (Ljdk8/byte_code/Server;)Ljdk8/byte_code/Condition; 
 #53 = Utf8               jdk8/byte_code/WaitFor 
 #54 = Utf8               waitFor 
 #55 = Utf8               (Ljdk8/byte_code/Condition;)V
 #56 = Utf8               isRunning 
 #57 = Utf8               java/lang/Boolean
 #58 = Utf8               booleanValue 
 #59 = Utf8               ()Z 
 #60 = Utf8               valueOf
 #61 = Utf8               (Z)Ljava/lang/Boolean;
 #62 = Class              #65        // java/lang/invoke/LambdaMetafactory 
 #63 = NameAndType        #66:#69    // metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
 #64 = NameAndType        #23:#24    // lambda$example$35:(Ljdk8/byte_code/Server;)Ljava/lang/Boolean;
 #65 = Utf8               java/lang/invoke/LambdaMetafactory 
 #66 = Utf8               metafactory 
 #67 = Class              #71        // java/lang/invoke/MethodHandles$Lookup 
 #68 = Utf8               Lookup
 #69 = Utf8 (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; 
 #70 = Class              #72        //java/lang/invoke/MethodHandles   
 #71 = Utf8               java/lang/invoke/MethodHandles$Lookup 
 #72 = Utf8               java/lang/invoke/MethodHandles
{
  public jdk8.byte_code.Example5();
   descriptor: ()V
   flags: ACC_PUBLIC
   Code:
     stack=1, locals=1, args_size=1
       0: aload_0
       1: invokespecial #1           // Method java/lang/Object."<init>":()V 
       4: return
    LineNumberTable:
      line 6: 0
    LocalVariableTable:
      Start Length Slot Name Signature
          0      5    0 this Ljdk8/byte_code/Example5;
void example() throws java.lang.InterruptedException;
  descriptor: ()V
  flags:
  Code:
    stack=2, locals=2, args_size=1
       0: new           #2           //class jdk8/byte_code/Server$HttpServer
       3: dup
       4: invokespecial #3           // Method jdk8/byte_code/Server$HttpServer."<init>":()V
       7: astore_1
       8: aload_1

       9: invokedynamic #4,  0       // InvokeDynamic #0:isSatisfied:(Ljdk8/byte_code/Server;)Ljdk8/byte_code/Condition;
       14: invokestatic  #5                  // Method jdk8/byte_code/WaitFor.waitFor:(Ljdk8/byte_code/Condition;)V
       17: return
      LineNumberTable:
        line 10: 0
        line 11: 8
        line 12: 17
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      18     0  this   Ljdk8/byte_code/Example5;
            8      10     1 server   Ljdk8/byte_code/Server;
    Exceptions:
      throws java.lang.InterruptedException
}

CentOS 7下Oracle 11G RAC静默安装避坑指南:从网络规划到共享存储配置全流程 本文详细介绍了在CentOS 7环境下进行Oracle 11G RAC静默安装的全流程,包括网络规划、共享存储配置和系统参数调优等关键步骤。特别针对静默安装过程中的常见问题提供了实用的避坑指南和优化建议,帮助技术人员高效完成企业级数据库部署。 阅读详情

相关推荐

Verilog基本代码结构及常用语句always、begin...end解读

Verilog基本代码结构及常用语句always、begin...end解读 线性反馈以为寄存器(LFSR)

weixin_62380586的博客 1万+

Lambda完整学习指南

Lambda表达式是Java SE 8中一个重要的新特性。lambda表达式允许你通过表达式来代替功能接口。lambda表达式就和方法一样,它提供了一个正常的参数列表和一个使用这些参数的主体(body,可以是一个表达式或一个代码块)。Lambda表达式还增强了集合库。Java Lambda表达式的一个重要用法是简化某些匿名内部类(Anonymous Classes)的写法。实际上Lambda表达式并不仅仅是匿名内部类的语法糖,JVM内部是通过invokedynamic指令来实现Lambda表达式的。

z_ssyy的博客 3472

多智能体强化学习论文——SEAC(NIPS 2020)

存在的问题&研究动机&研究思路 在稀疏奖励的环境下,多智能体的exploration存在效率不足等问题。 在IAC的基础上尝试加入重要性采样,使得每次更新智能体iii的参数时,不再仅仅使用智能体iii的数据,而是使用所有智能体的数据进行智能体iii数据的更新。 对于原始的IAC算法是on-policy的,而SEAC则是off-poligy的。 创新点 在每个智能体iii的actoriactor_iactori​和criticicritic_icritici​的更新过程中,都加入了重要性

我的AI笔记 1207

从入门到入土:Lambda完整学习指南,包教包会!

什么是Lambda表达式 Lambda表达式是Java SE 8中一个重要的新特性。lambda表达式允许你通过表达式来代替功能接口。lambda表达式就和方法一样,它提供了一个正常的参数列表和一个使用这些参数的主体(body,可以是一个表达式或一个代码块)。Lambda表达式还增强了集合库。 Java Lambda表达式的一个重要用法是简化某些匿名内部类(Anonymous Classes)...

Java笔记虾 6050

【AUCell打分】:评估一个基因集在单细胞转录组的每个细胞中特定的活性程度

AUCell使用曲线下面积来计算输入基因集的一个有意义的基因子集是否在每个细胞的表达基因中富集。AUC 分数在所有细胞中的分布允许探索特征的相对表达。由于评分方法是基于排名的,因此 AUCell 与基因表达单位和归一化程序无关。此外,由于细胞是单独评估的,因此可以很容易地应用于更大的数据集。

weixin_40695088的博客 1万+

19、硬件工程师笔试面试——无线通讯模块(2025版本)

例如,如果你的项目需要传输大量数据,如视频流或大数据文件,那么你可能需要一个高速率的模块,如支持802.11ac或802.11ax(WiFi 6)的模块。如果你的数据传输需求较小,如传感器数据,那么一个较低速率的模块,如蓝牙或Zigbee,可能就足够了。较高的频率(如5GHz)提供更大的带宽,支持更高的数据传输速率,但信号覆盖范围较小,穿透能力较弱。例如,在蓝牙通信中,一台设备作为主机,另一台设备作为从机,它们通过频率跳频的方式确定连接,并在连接建立后通过特定的协议进行数据交换。

XU157303764的博客 3226

详解Java之lambda

lambda的语法,函数式接口,lambda的使用,变量捕获,lambda在集合中的使用,lambda的优缺点。

. 1万+

博途PLC模糊PID控制(量化因子和比例因子)

参数"量化因子和比例因子",都是为了对清晰值进行比例变换而设置的,其作用是使变量按一定比例进行放大或缩小,以便和我们的模糊论域相匹配完成一一映射。这种变换对整个系统的工作性能也是有影响的。(其实相当于额外引入了比例作用,所以说模糊PID的调节是个系统工程)。限于本人能力,文中难免出现错误和不足,欢迎大家批评和指正。博途PLC的模糊PID控制完整算法可以参看下面这篇文章博途PLC模糊PID控制详解(SCL完整源代码+参数)_RXXW_Dor的博客-优快云博客。......

RXXW_Dor的博客 5269

Java Lambda 学习指南(一)

本书深入探讨了 lambda 及其支持功能的特点;例如函数接口和类型推断。阅读完本书后,您将:了解现代 Java 中的新功能概述深入了解 lambda,它们的背景、语法、实现细节以及如何以及何时使用它们理解函数与类之间的区别,以及这对 lambda 的相关性理解 lambda 和闭包之间的区别欣赏推动许多新功能的类型推断的改进能够使用方法引用并理解作用域和“有效最终”理解使用 lambda 时产生的字节码的差异能够推理异常和异常处理最佳实践在使用 lambda 时。

龙哥盟 1495

【全网最新OD题库】2026华为 OD 机试C卷 机考真题库清单(全真题库)含考点说明(华为OD+2025年C卷+2025年B卷+2025年A卷+E卷+D卷+C卷)

华为od机试,华为od机试真题,华为od机试E卷,华为odE卷,华为od机试真题E卷,华为OD,华为OD机试,华为OD机试真题,华为od机考,华为od机试D卷,华为od机试真题D卷,华为od手撕代码,华为od,华为od机试C卷,华为od e卷,华为2024e卷,od机试,2024E卷,华为OD机试E卷,什么是华为od,华为od介绍,全面了解华为od,2024华为od,如何备战华为od,华为od算法,华为od手撕代码,华为OD机试2024年最新题库,一文带你读懂华为OD,华为机试e卷,华为OD2025B卷、华

KJ.JK 3万+

STM32Cube高效开发教程<高级篇><FreeRTOS>(十八)-----软件定时器

一、 软件定时器概述声明:本人水平有限,博客可能存在部分错误的地方,请广大读者谅解并向本人反馈错误。本专栏博客参考《STM32Cube高效开发教程(高级篇)》,有意向的读者可以购买正版书籍辅助学习,本书籍由王维波老师、鄢志丹老师、王钊老师倾力打造,书籍内容干货满满。在FreeRTOS中,自动创建的任务有空闲任务和定时器服务任务。FreeRTOS可以通过定时器服务任务提供软件定时器功能。在某些对定时精度要求不太高,无须使用硬件定时器的情况下,我们可以使用FreeRTOS的软件定时器。

我的博客 157

Java·Lambda

本次文章主要为大家讲解了什么是数据结构中的Lambda,Lambda表达式是Java SE 8中一个重要的新特性。lambda表达式允许你通过表达式来代替功能接口。 lambda表达式就和方法一样,它提供了一个正常的参数列表和一个使用这些参数的主体(body,可以是一个表达式或一个代码块)。

xinhang10的博客 6145

基于FPGA的数字信号处理(11)--定点数的舍入模式(2)向最临近值取整nearest

基于FPGA的数字信号处理(11)--定点数的舍入模式(2)向最临近值取整nearest

孤独的单刀 5475

死磕Lambda表达式(二):Lambda的使用

在哪使用Lambda表达式?怎么样正确的使用Lambda表达式?

万猫学社 1万+

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Java中的Lambda

大家应该都知道面向对象的特性(抽象、封装、继承、多态)。其实在 出现之前,我们关注的往往是某一类对象应该具有什么样的属性,当然这也是面向对象的核心–对数据进行抽象。但是出现以后,这一点开始出现变化,在某种场景下,更加关注某一类共有的行为(这与之前的接口有些类似),这也就是提出函数式编程的目的。面向对象编程到面向行为编程的变化我们知道,对于一个变量,我们可以赋给其一个**“值”**。如果你想把**“一块代码”**赋给一个变量,应该怎么做呢?比如,我想把右边那块代码,赋给一个叫做的变量:在之前,这个是做不到的

qq_25775675的博客 4679

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Java8 Lambda表达式

Java8 Lambda表达式是简洁的匿名函数写法,用于实现函数式接口。基本语法为(参数) -> 表达式,支持类型推断和简化写法。核心概念包括函数式接口(如Predicate、Consumer、Function、Supplier等)、方法引用(四种类型:静态/实例/构造方法引用)和Stream API(用于集合处理)。方法引用简化了Lambda表达式,Stream API提供了函数式集合操作方式,包括中间操作和终端操作。这些特性使Java代码更简洁、可读性更强。

qq_44474810的博客 1036

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

【Java基础:系统性学习指南】Lambda与Stream API的现代化编程

摘要:本文聚焦于Java中Lambda表达式与Stream API的现代化编程特性。深入剖析Lambda的本质,通过字节码对比,阐述从匿名内部类到invokedynamic指令的转变。同时,探讨Stream API在使用时的性能陷阱,尤其是并行流的错误使用场景,并给出数据竞争案例。此外,详细介绍Optional类的正确用法,提倡使用orElseGet()进行延迟计算以替代orElse()。通过丰富的实操流程和完整代码示例,助力读者全面掌握这些现代化编程技巧。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 540

JAVA的Lambda

Lambda 表达式是简化函数式编程的重要工具,能够提高代码的可读性和灵活性。常见的函数式接口包括FunctionConsumerSupplierPredicate和BiFunction,这些接口可以帮助我们在不同场景下使用 Lambda 表达式。Lambda 表达式的基本模板易于理解,能够帮助我们在 Java 中实现更为灵活的函数式编程。

xjsj62728的博客 1208

Java Lambda

或参数列表:Lambda表达式的参数列表可以包含零个、一个或多个参数,参数类型可以省略,因为编译器能够根据上下文推断出参数的类型,这称为类型推断。箭头操作符:箭头操作符->将参数列表与Lambda主体隔开。Lambda主体:Lambda主体可以是一个表达式或一个代码块。如果是一个表达式,那么表达式的值会自动作为返回值;如果是一个代码块,那么必须使用return语句来返回值。在Java中,任何接口如果只有一个抽象方法,那么它就是一个函数式接口。这个概念在包中得到了广泛的应用。

曾续缘的博客 889

【Java系列】深入解析 Lambda表达式二

Lambda 表达式在 Java 中引入于 Java 8,它使得函数式编程的实现变得更加容易和直观。接下来,我们将详细探讨 Java 中 Lambda 表达式的语法、用法以及相关特性。

颜淡慕潇 1万+

AWS Lambda 与 Java

AWS Lambda是 Amazon Web Services(AWS)提供的一种无服务器计算服务,它允许开发者在无需管理服务器的情况下运行代码。AWS Lambda 的核心思想是“按需计算”,用户只需要为代码的实际运行时间付费,而不必关心底层的基础设施,如服务器的运维、扩展和可用性。AWS Lambda 的典型工作流程是基于事件触发的:当某个事件(如 HTTP 请求、文件上传、数据库更改等)发生时,Lambda 函数被自动触发,执行相应的业务逻辑。

Flying_Fish_roe的博客 1251

java lambda 是什么_自己理解Java中的lambda

lambda是什么“Lambda 表达式”(lambda expression)是一个匿名函数,Lambda表达式基于数学中的λ演算得名,直接对应于其中的lambda抽象(lambda abstraction),是一个匿名函数,即没有函数名的函数。Lambda表达式可以表示闭包(注意和数学传统意义上的不同)。将一个变量传入一个匿名函数然后对传入函数进行操作。由于java中并没有脱离类而存在的函数,...

weixin_42371226的博客 3881

深入理解 Java Lambda

Java Lambda Java Lambda Lambda Lambda 函数式接口 Lambda为什么可以做到类型推导?可以做到什么程度? 方法应用 Lambda和匿名类是什么关系?仅仅是语法糖? Java编译器如何处理Lambda? Lambda lambda名称的由来 许多年前,在计算机出来之前,有位名叫 Alonzo Church 的逻辑学家,他想证明 什么样...

何欣澄的博客 1891

Java lambda 以及 Lambda在集合中的使用

Java lambda 以及 Lambda在集合中的使用   java 1.8  demo示例 List  temp=serviceClienters.stream().filter(t ->t.getPubDate().equals(daySatisticsB.getMonthDate())).collect(Collectors.toList()); //linq查询

Solo_two的博客 7008

C++,C#,Java中的Lambda

1)捕获列表使用 Lambda 表达式来创建匿名函数。使用 lambda声明运算符=> 从其主体中分离 lambda 参数列表。若要创建 Lambda 表达式,需要在 Lambda 运算符左侧指定输入参数(如果有),然后在另一侧输入表达式或语句块。任何 Lambda 表达式都可以转换为委托类型。Lambda 表达式可以转换的委托类型由其参数和返回值的类型定义。如果 lambda 表达式不返回值,则可以将其转换为Action委托类型之一;否则,可将其转换为Func委托类型之一。

Iamme 1534
上一篇: Java Lambda 学习指南(一)
下一篇: Java 项目学习指南(一)
绝不原创的飞龙
绝不原创的飞龙 优质创作者: 人工智能、数据科学与机器学习技术领域 优质创作者: 人工智能、数据科学与机器学习技术领域
博客等级 码龄15年 4万+粉丝 2万+原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值