Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Java Lambdas

You're reading from  Learning Java Lambdas

Product type Book
Published in Mar 2017
Publisher
ISBN-13 9781787282087
Pages 114 pages
Edition 1st Edition
Languages
Author (1):
Toby Weston Toby Weston
Profile icon Toby Weston
Toc

Example 4 (with Method Reference)


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
  }
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime