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 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
}
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