'. '

Lambdas

From APIDesign

(Difference between revisions)
Jump to: navigation, search
(New page: Lambdas are Java implementation of Closures and are coming with JDK8. == Don't Know the Syntax? == Yesterday I had a duty at NetBeans JavaOne2013 booth. Somebody ...)
Line 23: Line 23:
</source>
</source>
-
No luck either. I gave up and rewrote the code to old good inner class syntax:
+
No luck either. I gave up and rewrote the code to old good verbose but familiar inner class syntax:
<source lang="java">
<source lang="java">
-
doRun(new Runnable() { public void run() {
+
public static void main(String... args) {
-
System.out.println("Hello World!");
+
doRun(new Runnable() {
-
}});
+
@Override
 +
public void run() {
 +
System.out.println("Hello World!");
 +
}
 +
});
 +
}
</source>
</source>
and suddenly a hint appeared:
and suddenly a hint appeared:

Revision as of 17:24, 24 September 2013

Lambdas are Java implementation of Closures and are coming with JDK8.

Don't Know the Syntax?

Yesterday I had a duty at NetBeans JavaOne2013 booth. Somebody asked whether NetBeans support lambda. Sure, NetBeans 7.4 do! was my answer. But how to demonstrate that? I tried:

class LamdaTest {
  static void doRun(Runnable r) {
    r.run();
  }
 
  public static void main(String... args) {
    doRun({ System.out.println("Hello World!"); });
  }
}

it did not compile. Then I tried to change the lambda line to:

doRun( => { System.out.println("Hello World!"); });

No luck either. I gave up and rewrote the code to old good verbose but familiar inner class syntax:

public static void main(String... args) {
    doRun(new Runnable() {
        @Override
        public void run() {
            System.out.println("Hello World!");
        }
    });
  }

and suddenly a hint appeared:

Personal tools
buy