Home | History | Annotate | Download | only in LambdaTest
      1 .class public LHelloWorldLambda;
      2 
      3 #Ye olde hello world application (with lambdas!)
      4 #To assemble and run this on a phone or emulator:
      5 #
      6 #java -jar smali.jar -o classes.dex HelloWorldLambda.smali HelloWorldFunctionalInterface.smali
      7 #zip HelloWorld.zip classes.dex
      8 #adb push HelloWorld.zip /data/local
      9 #adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld
     10 #
     11 #if you get out of memory type errors when running smali.jar, try
     12 #java -Xmx512m -jar smali.jar HelloWorldLambda.smali
     13 #instead
     14 
     15 .super Ljava/lang/Object;
     16 
     17 .method public static doHelloWorld(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
     18     .registers 6 # 4 parameters, 2 locals
     19     liberate-variable v0, p0, "helloworld"
     20 
     21     sget-object v1, Ljava/lang/System;->out:Ljava/io/PrintStream;
     22     invoke-virtual {v1, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
     23 
     24     return-void
     25 .end method
     26 
     27 .method public static main([Ljava/lang/String;)V
     28     .registers 9 # 1 parameter, 8 locals
     29 
     30     sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
     31 
     32     const-string v1, "Hello World!"
     33     const-string v2, "How" # vD
     34     const-string v3, "are" # vE
     35     const-string v4, "you" # vF
     36     const-string v5, "doing?" # vG
     37 
     38     capture-variable v1, "helloworld"
     39 
     40     # TODO: do I need to pass the type of the lambda's functional interface here as a type id?
     41     create-lambda v1, LHelloWorldLambda;->doHelloWorld(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
     42     # Method descriptor is not required here, because only the single-abstract method is ever invoked.
     43     invoke-lambda v1, {v2, v3, v4, v5}
     44 
     45     box-lambda v6, v1
     46     invoke-virtual {v6, v2, v3, v4, v5}, LHelloWorldFunctionalInterface;->applyFourStrings(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
     47 
     48     # FIXME: should be \HelloWorldFunctionalInterface; instead of L...;
     49 
     50     # TODO: do we really need the type descriptor here at all?
     51     unbox-lambda v7, v6, LHelloWorldFunctionalInterface;
     52     invoke-lambda v7, {v2, v3, v4, v5}
     53 
     54     return-void
     55 .end method
     56