changeset 662:13e106a36674

Updated prototype in order to reflect latest changes in 'State of the Lambda document' Summary of changes: *) new syntax ( a lambda is now introduced using #{ comma-separated-args -> body }, as in # { x -> print(x); } ) *)'this' in lambda expressions is lexically scoped *) updated DA/DU rules to allow lambda expression to recursively refer to itself (via SAM ref)
author mcimadamore
date Mon, 18 Oct 2010 17:21:50 +0100
parents 52681eb717e7
children caadb412a4a6
files src/share/classes/com/sun/source/tree/LambdaExpressionTree.java src/share/classes/com/sun/tools/javac/comp/Attr.java src/share/classes/com/sun/tools/javac/comp/Enter.java src/share/classes/com/sun/tools/javac/comp/Flow.java src/share/classes/com/sun/tools/javac/comp/Resolve.java src/share/classes/com/sun/tools/javac/comp/Unlambda.java src/share/classes/com/sun/tools/javac/parser/JavacParser.java src/share/classes/com/sun/tools/javac/parser/Token.java src/share/classes/com/sun/tools/javac/tree/JCTree.java src/share/classes/com/sun/tools/javac/tree/TreeCopier.java src/share/classes/com/sun/tools/javac/tree/TreeInfo.java src/share/classes/com/sun/tools/javac/tree/TreeMaker.java src/share/classes/com/sun/tools/javac/tree/TreeScanner.java test/tools/javac/defender/Pos01.java test/tools/javac/lambda/BadLambdaPos.java test/tools/javac/lambda/BadLambdaPos.out test/tools/javac/lambda/BadTargetType.java test/tools/javac/lambda/ExceptionTransparency01.java test/tools/javac/lambda/ExceptionTransparency03.java test/tools/javac/lambda/LambdaCapture01.java test/tools/javac/lambda/LambdaCapture02.java test/tools/javac/lambda/LambdaCapture03.java test/tools/javac/lambda/LambdaCapture04.java test/tools/javac/lambda/LambdaCapture05.java test/tools/javac/lambda/LambdaConv01.java test/tools/javac/lambda/LambdaConv02.java test/tools/javac/lambda/LambdaConv03.java test/tools/javac/lambda/LambdaConv05.java test/tools/javac/lambda/LambdaConv06.java test/tools/javac/lambda/LambdaConv07.java test/tools/javac/lambda/LambdaConv08.java test/tools/javac/lambda/LambdaConv09.java test/tools/javac/lambda/LambdaConv10.java test/tools/javac/lambda/LambdaConversionTest.java test/tools/javac/lambda/LambdaExpr01.java test/tools/javac/lambda/LambdaExpr02.java test/tools/javac/lambda/LambdaExpr04.java test/tools/javac/lambda/LambdaExpr05.java test/tools/javac/lambda/LambdaExprNotVoid.java test/tools/javac/lambda/LambdaExprNotVoid.out test/tools/javac/lambda/LambdaScope01.java test/tools/javac/lambda/LambdaScope02.java test/tools/javac/lambda/MethodReference07.java test/tools/javac/lambda/MethodReference12.java test/tools/javac/lambda/NakedThis.java test/tools/javac/lambda/TargetType01.java test/tools/javac/lambda/TargetType01.out test/tools/javac/lambda/TargetType02.java test/tools/javac/lambda/TargetType03.java test/tools/javac/lambda/TargetType04.java test/tools/javac/lambda/TargetType04.out test/tools/javac/lambda/TargetType05.java test/tools/javac/lambda/TargetType06.java test/tools/javac/lambda/TargetType07.java test/tools/javac/lambda/TargetType08.java test/tools/javac/lambda/TargetType10.java test/tools/javac/lambda/TargetType11.java test/tools/javac/lambda/TargetType12.java test/tools/javac/lambda/TargetType13.java
diffstat 59 files changed, 534 insertions(+), 412 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/source/tree/LambdaExpressionTree.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/source/tree/LambdaExpressionTree.java	Mon Oct 18 17:21:50 2010 +0100
@@ -35,5 +35,4 @@
 public interface LambdaExpressionTree extends ExpressionTree {
     List<? extends VariableTree> getParameters();
     Tree getBody();
-    ExpressionTree getIdentifier();
 }
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Oct 18 17:21:50 2010 +0100
@@ -408,10 +408,6 @@
      */
     Env<AttrContext> env;
 
-    /** Visitor argument: enclosing tree kind
-     */
-    int enclKind = -1;
-
     /** Visitor argument: the currently expected proto-kind.
      */
     int pkind;
@@ -436,16 +432,14 @@
      *  @param pkind   The protokind visitor argument.
      *  @param pt      The prototype visitor argument.
      */
-    Type attribTree(JCTree tree, Env<AttrContext> env, int pkind, int enclKind, Type pt, String errKey) {
+    Type attribTree(JCTree tree, Env<AttrContext> env, int pkind, Type pt, String errKey) {
         Env<AttrContext> prevEnv = this.env;
         int prevPkind = this.pkind;
-        int prevEnclKind = this.enclKind;
         Type prevPt = this.pt;
         String prevErrKey = this.errKey;
         try {
             this.env = env;
             this.pkind = pkind;
-            this.enclKind = enclKind;
             this.pt = pt;
             this.errKey = errKey;
             tree.accept(this);
@@ -458,7 +452,6 @@
         } finally {
             this.env = prevEnv;
             this.pkind = prevPkind;
-            this.enclKind = prevEnclKind;
             this.pt = prevPt;
             this.errKey = prevErrKey;
         }
@@ -467,7 +460,7 @@
     /** Derived visitor method: attribute an expression tree.
      */
     Type attribTree(JCTree tree, Env<AttrContext> env, int pkind, Type pt) {
-        return attribTree(tree, env, pkind, -1, pt, "incompatible.types");
+        return attribTree(tree, env, pkind, pt, "incompatible.types");
     }
 
     public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt) {
@@ -475,7 +468,7 @@
     }
 
     public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt, String key) {
-        return attribTree(tree, env, VAL, -1, pt.tag != ERROR ? pt : Type.noType, key);
+        return attribTree(tree, env, VAL, pt.tag != ERROR ? pt : Type.noType, key);
     }
 
     /** Derived visitor method: attribute an expression tree with
@@ -527,7 +520,7 @@
         ListBuffer<Type> argtypes = new ListBuffer<Type>();
         for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail)
             argtypes.append(chk.checkNonVoid(
-                l.head.pos(), types.upperBound(attribTree(l.head, env, VAL, JCTree.APPLY, Infer.anyPoly, "incompatible.types"))));
+                l.head.pos(), types.upperBound(attribTree(l.head, env, VAL, Infer.anyPoly, "incompatible.types"))));
         return argtypes.toList();
     }
 
@@ -1498,9 +1491,6 @@
             Type mtype = attribTree(tree.meth,
                     localEnv,
                     VAL,
-                    tree.isMethodReference() ?
-                        JCTree.REFERENCE :
-                        JCTree.APPLY,
                     mpt,
                     "incompatible.types");
             if (localEnv.info.varArgs)
@@ -1749,7 +1739,7 @@
                 if (allowLambda &&
                         identifyLambdaCandidate &&
                         clazztype.tag == CLASS &&
-                        (enclKind == JCTree.APPLY || pt.tag == CLASS) &&
+                        lambdaOrReferenceAllowed(tree) &&
                         !types.findSAM(clazztype).isErroneous()) {
                     log.note(tree.def, "potential.lambda.found");
                 }
@@ -2008,7 +1998,7 @@
     Env<AttrContext> lambdaEnvironment(JCLambda tree, final Type targetType) {
 
         //create synthetic outer class symbol hoisting the lambda
-        ClassSymbol lambdaClassSym = makeLambdaClass(targetType, env.info.scope.owner,
+        ClassSymbol lambdaClassSym = makeLambdaClass(env.info.scope.owner,
                 LAMBDA | SYNTHETIC);
 
         JCClassDecl classdef = make.ClassDef(make.Modifiers(lambdaClassSym.flags()),
@@ -2027,7 +2017,6 @@
 
         //create synthetic lambda symbol
         MethodSymbol lambdaSym = makeLambdaSymbol(targetType, lambdaClassSym);
-        lambdaClassSym.members_field.enter(lambdaSym);
 
         JCBlock body = tree.getBodyKind() == JCLambda.BodyKind.EXPRESSION ?
             make.Block(0, List.<JCStatement>of(make.Return((JCExpression)tree.body))) :
@@ -2047,17 +2036,10 @@
         Env<AttrContext> newEnv = memberEnter.methodEnv(lambda, outerEnv);
         newEnv.info.scope.owner = lambda.sym;
         
-        //add 'this'
-        VarSymbol thisSym = new VarSymbol(FINAL | HASINIT,
-                names._this,
-                lambdaClassSym.type,
-                lambdaClassSym);
-        newEnv.info.scope.enter(thisSym);
-        
         return newEnv;
     }
     //where
-    private ClassSymbol makeLambdaClass(Type targetType, Symbol owner, long flags) {
+    private ClassSymbol makeLambdaClass(Symbol owner, long flags) {
 
         ClassSymbol lambdaClassSym =
                     new ClassSymbol(flags, names.empty, null, owner);
@@ -2067,20 +2049,12 @@
                 lambdaClassSym);
 
         enter.setEnclosingType(lambdaClassSym, lambdaClassSym.owner);
+
+        if (lambdaClassSym.type.getEnclosingType().tag != NONE) {
+            lambdaClassSym.flags_field |= OUTER_ACCESS;            
+        }
         lambdaClassSym.members_field = new Scope(lambdaClassSym);
 
-        Type superType = types.isFunctionType(targetType) ?
-            syms.methodHandleType :
-            targetType;
-
-        if (superType.isInterface()) {
-            ((ClassType)lambdaClassSym.type).supertype_field = syms.objectType;
-            ((ClassType)lambdaClassSym.type).interfaces_field = List.of(superType);
-        }
-        else {
-            ((ClassType)lambdaClassSym.type).supertype_field = superType;
-        }
-
         return lambdaClassSym;
     }
     //where
@@ -2116,18 +2090,12 @@
      */
     @Override
     public void visitLambda(JCLambda that) {
-        if (enclKind != JCTree.APPLY && pt.tag != CLASS) {
-            //lambda only allowed in assignment or method invocation context
+        if (!lambdaOrReferenceAllowed(that)) {
+            //lambda only allowed in assignment or method invocation/cast context
             log.error(that.pos(), "unexpected.lambda");
         }
         
-        Type targetType = that.clazz != null ?
-            attribType(that.clazz, env) :
-            Type.noType;
-
-        final Type typeToCheck = targetType != Type.noType ?
-            targetType :
-            pt;
+        Type typeToCheck = lambdaOrReferenceTargetType(that);
 
         //if the lambda expression needs parameter inference and/or the target
         //type is unknown (e.g. the lambda position is in argument position)
@@ -2153,6 +2121,30 @@
         }
     }
 
+    boolean lambdaOrReferenceAllowed(JCTree lambdaOrReference) {
+        if (env.tree.getTag() == JCTree.TYPECAST &&
+                ((JCTypeCast)env.tree).expr == lambdaOrReference) {
+            return true;
+        } else if (env.tree.getTag() == JCTree.APPLY) {
+            JCMethodInvocation apply = (JCMethodInvocation)env.tree;
+            for (JCTree arg : apply.args) {
+                if (arg == lambdaOrReference) {
+                    return true;
+                }
+            }
+            return false;
+        } else {
+            return pt.tag == CLASS;
+        }
+    }
+
+    Type lambdaOrReferenceTargetType(JCTree lambdaOrReference) {
+        switch (env.tree.getTag()) {
+            case JCTree.TYPECAST: return ((JCTypeCast)env.tree).clazz.type;
+            default: return pt;
+        }
+    }
+
     /*
      * Prepare for lambda inference. Replicate the AST and perform a first round
      * of lambda attribution (see below) in which lambda return/thrown types
@@ -2382,7 +2374,7 @@
                 targetType.getThrownTypes(),
                 syms.methodHandleType.tsym);
 
-        that.targetType = samOrFunctionType;
+        that.targetType = superType;
         that.sym = localEnv.enclMethod.sym;
         return samOrFunctionType;
     }
@@ -2517,8 +2509,9 @@
     public void visitTypeCast(JCTypeCast tree) {
         Type clazztype = attribType(tree.clazz, env);
         chk.validate(tree.clazz, env);
-        Type exprtype = attribExpr(tree.expr, env, Infer.anyPoly);
-        Type owntype = chk.checkCastable(tree.expr.pos(), env, exprtype, clazztype);
+        Env<AttrContext> localEnv = env.dup(tree);
+        Type exprtype = attribExpr(tree.expr, localEnv, Infer.anyPoly);
+        Type owntype = chk.checkCastable(tree.expr.pos(), localEnv, exprtype, clazztype);
         if (exprtype.constValue() != null)
             owntype = cfolder.coerce(exprtype, owntype);
         result = check(tree, capture(owntype), VAL, pkind, pt);
@@ -2596,18 +2589,14 @@
             checkInit(tree, env, v, false);
 
             // If symbol is a local variable accessed from an embedded
-            // inner class check that it is final.
+            // inner class (not a lambda!) check that it is final.
             if (v.owner.kind == MTH &&
-                v.owner != env.info.scope.owner &&
-                (v.flags_field & FINAL) == 0) {
-                if ((env.enclClass.sym.flags() & LAMBDA) != 0) {
-                    v.flags_field |= LAMBDA;
-                }
-                else {
-                    log.error(tree.pos(),
-                              "local.var.accessed.from.inner.ctx.needs.final",
-                              v, diags.fragment("icls"));
-                }
+                    v.owner != env.info.scope.owner &&
+                    (v.flags_field & FINAL) == 0 &&
+                    (env.enclClass.sym.flags() & LAMBDA) == 0) {
+                log.error(tree.pos(),
+                        "local.var.accessed.from.inner.ctx.needs.final",
+                        v, diags.fragment("icls"));
             }
 
             // If we are expecting a variable (as opposed to a value), check
@@ -2638,8 +2627,7 @@
     }
 
     public void visitReference(JCMemberReference tree) {
-        //this code should be removed from the final version
-        if (enclKind != JCTree.APPLY && pt.tag != CLASS) {
+        if (!lambdaOrReferenceAllowed(tree)) {
             //method references only allowed in assignment or method invocation context
             log.error(tree.pos(), "unexpected.meth.reference");
         }
@@ -2686,7 +2674,7 @@
         assert sym != null;
         tree.sym = sym;
         // FIXME: Instantiate MH<R(A...)> with type parameters from sym.
-        result = check(tree, owntype, VAL, pkind, pt);
+        result = check(tree, owntype, VAL, pkind, lambdaOrReferenceTargetType(tree));
     }
     //where
     private Type makeMethodReferenceType(JCMethodInvocation tree) {
@@ -2810,7 +2798,7 @@
             } else {
                 // Check if type-qualified fields or methods are static (JLS)
                 if ((sym.flags() & STATIC) == 0 &&
-                    enclKind != JCTree.REFERENCE &&
+                    env.next.tree.getTag() != JCTree.REFERENCE &&
                     sym.name != names._super &&
                     (sym.kind == VAR || sym.kind == MTH)) {
                     rs.access(rs.new StaticError(sym),
--- a/src/share/classes/com/sun/tools/javac/comp/Enter.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java	Mon Oct 18 17:21:50 2010 +0100
@@ -416,7 +416,8 @@
             // (its "enclosing instance class"), provided such a class exists.
             Symbol owner1 = owner;
             while ((owner1.kind & (VAR | MTH)) != 0 &&
-                   (owner1.flags_field & STATIC) == 0) {
+                   (owner1.flags_field & STATIC) == 0 &&
+                   (owner1.flags_field & LAMBDA) == 0) {
                 owner1 = owner1.owner;
             }
             if (owner1.kind == TYP) {
--- a/src/share/classes/com/sun/tools/javac/comp/Flow.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java	Mon Oct 18 17:21:50 2010 +0100
@@ -433,8 +433,12 @@
             log.error(pos, "var.might.not.have.been.initialized",
                       sym);
             inits.incl(sym.adr);
-        } else if (inLambda &&
-                (sym.flags() & LAMBDA) != 0 &&
+        }
+    }
+
+    void checkEffectivelyFinal(DiagnosticPosition pos, VarSymbol sym) {
+        if (inLambda &&
+                sym.owner.kind == MTH &&
                 (sym.flags() & EFFECTIVELY_FINAL) == 0) {
             log.error(pos, "cant.ref.non.effectively.final.var",
                     sym);
@@ -1309,9 +1313,9 @@
         try {
             inLambda = true;
             caught = List.of(syms.throwableType); //inhibit exception checking
-            thrown = List.nil();
-            uninits = uninits.dup();
-            inits = inits.dup();
+            thrown = List.nil();            
+            inits = inits.orSet(uninits);
+            uninits.clear();
             pendingExits = new ListBuffer<PendingExit>();
             for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
                 JCVariableDecl def = l.head;
@@ -1436,6 +1440,7 @@
     public void visitIdent(JCIdent tree) {
         if (tree.sym.kind == VAR) {
             checkInit(tree.pos(), (VarSymbol)tree.sym);
+            checkEffectivelyFinal(tree.pos(), (VarSymbol)tree.sym);
             referenced(tree.sym);
         }
     }
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Mon Oct 18 17:21:50 2010 +0100
@@ -1669,9 +1669,17 @@
      * JLS2 8.8.5.1 and 15.9.2
      */
     Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t) {
-        Type thisType = (((t.tsym.owner.kind & (MTH|VAR)) != 0)
-                         ? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this)
-                         : resolveSelfContaining(pos, env, t.tsym)).type;
+        final Type thisType;
+        if ((t.tsym.owner.kind & (MTH|VAR)) != 0) {
+            do {
+                //lambda should never be picked as implicit this
+                t = t.getEnclosingType();
+            }
+            while ((t.tsym.flags() & LAMBDA) != 0);
+            thisType = resolveSelf(pos, env, t.tsym, names._this).type;
+        } else {
+            thisType = resolveSelfContaining(pos, env, t.tsym).type;
+        }
         if (env.info.isSelfCall && thisType.tsym == env.enclClass.sym)
             log.error(pos, "cant.ref.before.ctor.called", "this");
         return thisType;
--- a/src/share/classes/com/sun/tools/javac/comp/Unlambda.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/Unlambda.java	Mon Oct 18 17:21:50 2010 +0100
@@ -91,8 +91,7 @@
         }
     }
 
-
-
+    @Override
     public void visitLambda(JCLambda tree) {
         if (types.isFunctionType(tree.targetType)) {
             //lambda expression whose target is a function type are still
@@ -107,9 +106,29 @@
         //   class <anon> extends SAMClass { ... }
 
         ClassSymbol samClassSym = (ClassSymbol)tree.sym.owner;
+
+        //add this
+        VarSymbol thisSym = new VarSymbol(Flags.FINAL | Flags.HASINIT,
+                    names._this,
+                    samClassSym.type,
+                    samClassSym);
+        samClassSym.members().enter(thisSym);
+        
         samClassSym.flatname = chk.localClassName(samClassSym);
         chk.compiled.put(samClassSym.flatname, samClassSym);
 
+        Type superType = types.isFunctionType(tree.targetType) ?
+            syms.methodHandleType :
+            tree.targetType;
+
+        if (superType.isInterface()) {
+            ((ClassType)samClassSym.type).supertype_field = syms.objectType;
+            ((ClassType)samClassSym.type).interfaces_field = List.of(superType);
+        }
+        else {
+            ((ClassType)samClassSym.type).supertype_field = superType;
+        }
+
         JCClassDecl samClassDecl = make.ClassDef(
                 make.Modifiers(samClassSym.flags_field),
                 names.empty,
@@ -137,6 +156,7 @@
         samMethodDecl.body = makeLambdaBody(tree);
         samClassDecl.defs = List.<JCTree>of(samConstrDecl, samMethodDecl);
         samClassSym.members().enter(samConstrDecl.sym);
+        samClassSym.members().enter(samMethodDecl.sym);
 
         JCNewClass newClass = make.NewClass(null,
                 List.<JCExpression>nil(),
@@ -207,4 +227,76 @@
         }
         return body;
     }
+
+    @Override
+    public void visitVarDef(final JCVariableDecl tree) {
+        if (tree.sym.owner.kind == Kinds.MTH &&
+                tree.init != null &&
+                tree.init.getTag() == JCTree.LAMBDA) {
+
+            //if this is a local variable initialized with a lambda expression
+            //we need to check whether the variable is referenced from the lambda
+
+            super.visitVarDef(tree);
+            JCClassDecl c = ((JCNewClass)tree.init).def;
+            final VarSymbol capturedVar = new VarSymbol(0, names.fromString("$f"), c.type, c.sym);
+
+            //references to variable under initialization from lambda body
+            //are automatically turned into references to a synthetic field
+            //of the desugared lambda class
+            
+            class LambdaVarInitPatcher extends TreeScanner {
+                boolean needsCapture = true;
+                @Override
+                public void visitIdent(JCIdent that) {
+                    if (tree.sym == that.sym) {
+                        needsCapture = true;
+                        that.sym = capturedVar;
+                        that.name = capturedVar.name;
+                    }
+                }
+            }
+            LambdaVarInitPatcher lvis = new LambdaVarInitPatcher();
+            lvis.scan(tree.init);
+            if (lvis.needsCapture) {
+
+                //if the previous step has replaced some references to the
+                //variable being initialized, generate extra synthetic field
+                //append to desugared lambda class and initialize it
+
+                c.sym.members().enter(capturedVar);
+                JCVariableDecl capturedVarDecl = make.VarDef(capturedVar, null);
+                c.defs = c.defs.prepend(capturedVarDecl);
+                JCIdent varRef = make.Ident(tree.sym);
+                JCExpression capturedVarRef = make.Select(
+                        make.TypeCast(c.type, varRef).setType(c.type),
+                        capturedVar);
+                tailStats.append(make.Exec(make.Assign(capturedVarRef, varRef).setType(tree.type)));
+            }
+        } else {
+            super.visitVarDef(tree);
+        }
+    }
+
+    /*
+     * list buffer containing additional statements to be generated
+     * during translation of a block - this might be required in case
+     * a single block statement gets desugared into multiple statements
+     * (and a block cannot be used)
+     */
+    ListBuffer<JCStatement> tailStats = ListBuffer.lb();
+
+    @Override
+    public void visitBlock(JCBlock tree) {
+        ListBuffer<JCStatement> newStats = ListBuffer.lb();
+        for (JCStatement stat : tree.stats) {
+            newStats = newStats.append(translate(stat));
+            if (tailStats.nonEmpty()) {
+                newStats = newStats.appendList(tailStats);
+                tailStats.clear();
+            }
+        }
+        tree.stats = newStats.toList();
+        result = tree;
+    }
 }
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Oct 18 17:21:50 2010 +0100
@@ -951,7 +951,7 @@
      *                 | "[" Expression "]"
      *  TypeSelector   = "." Ident [TypeArguments]
      *  SuperSuffix    = Arguments | "." Ident [Arguments]
-     */    
+     */
     protected JCExpression term3() {
         int pos = S.pos();
         JCExpression t;
@@ -980,7 +980,7 @@
             } else return illegal();
             break;        
         case HASH:
-            t = lambdaOrFunctionType();
+            t = lambdaExpressionOrStatement();
             break;
         case LPAREN:
             if (typeArgs == null && (mode & EXPR) != 0) {
@@ -1200,11 +1200,6 @@
                             t = innerCreator(pos1, typeArgs, t);
                             typeArgs = null;
                             break loop;
-                        case LPAREN:
-                            //creates lambda call --- standard apply
-                            checkLambda();
-                            t = arguments(typeArgs, toP(F.at(S.pos()).Select(t, names.empty)));
-                            break loop;
                         default:
                             break;
                         }
@@ -1220,64 +1215,62 @@
                         illegal(annos.head.pos);
                     }
                     break loop;
+                case LT:
+                    if ((mode & NOLAMBDA) == 0) {
+                        S.pushState();
+                        int oldPos = S.pos();
+                        S.nextToken();
+                        int prevMode = mode;
+                        mode |= EXPR | TYPE | TYPEARG| NOLAMBDA | DISJOINT;
+                        JCExpression t1 = term3();
+                        if ((mode & TYPE) != 0 &&
+                            (S.token() == COMMA || S.token() == GT)) {
+                            mode = prevMode;
+                            checkGenerics(oldPos);
+                            mode = TYPE;
+                            ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
+                            args.append(t1);
+                            while (S.token() == COMMA) {
+                                S.nextToken();
+                                args.append(typeArgument());
+                            }
+                            if (S.token() == GT) {
+                                accept(GT);
+                                S.mergeState();
+                                t = toP(F.at(pos).TypeApply(t, args.toList()));
+                                if (S.token() == DOT) {
+                                    S.mergeState();
+                                    S.pushState();
+                                    accept(DOT);
+                                    if (S.token() == HASH) {
+                                        S.mergeState();
+                                        accept(HASH);
+                                        t = memberReferenceSuffix(S.pos(), t);
+                                        break loop;
+                                    }
+                                    S.popState();
+                                }
+                                break;
+                            }
+                        }
+                        mode = EXPR;
+                        S.popState();
+                    }
+                    break loop;
+                case HASH:
+                    mode = EXPR;
+                    if (typeArgs != null) return illegal();
+                    accept(HASH);
+                    t = memberReferenceSuffix(S.pos(), t);
+                    break loop;
                 default:
-                    if (S.token() == HASH) {
-                        mode = EXPR;
-                        if (typeArgs != null) return illegal();
-                        int pos2 = S.pos();
-                        accept(HASH);
-                        t = (S.token() == LPAREN ||
-                                S.token() == LBRACE) ?
-                                    lambdaExpressionOrStatement(t) :
-                                    memberReferenceSuffix(pos2, t);
-                        break loop;
-                    }
                     break loop;
                 }
             }
             if (typeArgs != null) illegal();            
             if ((mode & NOLAMBDA) != 0) {
                 t = typeArgumentsOpt(t);
-            }
-            else if (S.token() == LT) {                
-                S.pushState();
-                int oldPos = S.pos();
-                S.nextToken();
-                int prevMode = mode;                
-                mode |= EXPR | TYPE | TYPEARG| NOLAMBDA | DISJOINT;
-                JCExpression t1 = term3();                
-                if ((mode & TYPE) != 0 &&
-                    (S.token() == COMMA || S.token() == GT)) {
-                    checkGenerics(oldPos);
-                    mode = TYPE;
-                    ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
-                    args.append(t1);
-                    while (S.token() == COMMA) {
-                        S.nextToken();
-                        args.append(typeArgument());
-                    }
-                    if (S.token() == GT) {
-                        accept(GT);
-                        S.mergeState();
-                        t = toP(F.at(pos).TypeApply(t, args.toList()));
-                        if (S.token() == HASH) {
-                            accept(HASH);
-                            t = S.token() == LBRACE ||
-                                    S.token() == LPAREN ?
-                                        lambdaExpressionOrStatement(t) :
-                                        memberReferenceSuffix(S.pos(), t);
-                        }
-                    }
-                    else {
-                        mode = EXPR;
-                        S.popState();
-                    }
-                } else {
-                    mode = prevMode;
-                    S.popState();                    
-                    t = typeArgumentsOpt(t);
-                }
-            }
+            }            
             break;
         case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:
         case DOUBLE: case BOOLEAN:
@@ -1356,31 +1349,24 @@
             } else if (S.token() == DOT) {
                 S.nextToken();
                 typeArgs = typeArgumentsOpt(EXPR);
-                if (S.token() == LPAREN) {
-                    //creates lambda call --- standard apply
-                    checkLambda();
-                    t = arguments(typeArgs, toP(F.at(S.pos()).Select(t, names.empty)));
-                }
-                else {
-                    if (S.token() == SUPER && (mode & EXPR) != 0) {
-                        mode = EXPR;
-                        t = to(F.at(pos1).Select(t, names._super));
-                        S.nextToken();
-                        t = arguments(typeArgs, t);
-                        typeArgs = null;
-                    } else if (S.token() == NEW && (mode & EXPR) != 0) {
-                        if (typeArgs != null) return illegal();
-                        mode = EXPR;
-                        int pos2 = S.pos();
-                        S.nextToken();
-                        if (S.token() == LT) typeArgs = typeArguments();
-                        t = innerCreator(pos2, typeArgs, t);
-                        typeArgs = null;
-                    } else {
-                        t = toP(F.at(pos1).Select(t, ident()));
-                        t = argumentsOpt(typeArgs, typeArgumentsOpt(t));
-                        typeArgs = null;
-                    }
+                if (S.token() == SUPER && (mode & EXPR) != 0) {
+                    mode = EXPR;
+                    t = to(F.at(pos1).Select(t, names._super));
+                    S.nextToken();
+                    t = arguments(typeArgs, t);
+                    typeArgs = null;
+                } else if (S.token() == NEW && (mode & EXPR) != 0) {
+                    if (typeArgs != null) return illegal();
+                    mode = EXPR;
+                    int pos2 = S.pos();
+                    S.nextToken();
+                    if (S.token() == LT) typeArgs = typeArguments();
+                    t = innerCreator(pos2, typeArgs, t);
+                    typeArgs = null;
+                } else {
+                    t = toP(F.at(pos1).Select(t, ident()));
+                    t = argumentsOpt(typeArgs, typeArgumentsOpt(t));
+                    typeArgs = null;
                 }
             } else if ((mode & EXPR) != 0 && S.token() == HASH) {
                 if (typeArgs != null) return illegal();
@@ -1406,66 +1392,84 @@
         return toP(t);
     }
 
-    JCExpression lambdaOrFunctionType() {
+    JCExpression lambdaExpressionOrStatement() {
         checkLambda();
         int pos = S.pos();
-        accept(HASH);
-        return S.token() == LPAREN ||
-                S.token() == LBRACE ?
-            lambdaExpressionOrStatement(null, pos) :
-            functionType();
+        accept(HASH);        
+        return lambdaExpressionOrStatement(pos);
     }
 
-    JCExpression lambdaExpressionOrStatement(JCExpression clazz) {
-        int pos = clazz.getStartPosition();
-        return lambdaExpressionOrStatement(clazz, pos);
+    JCExpression lambdaExpressionOrStatement(int pos) {
+        return lambdaExpressionOrStatement(pos, isLambdaWithArgs());
+    }
+
+    boolean isLambdaWithArgs() {
+        S.pushState();
+        accept(LBRACE);
+        boolean arrowFound = false;
+        loop: while (S.token() != EOF) {
+            switch (S.token()) {
+                case RBRACE: break loop;
+                case ARROW: arrowFound = true; break loop;
+            }
+            S.nextToken();
+        }
+        S.popState();
+        return arrowFound;
     }
 
     @SuppressWarnings("fallthrough")
-    JCExpression lambdaExpressionOrStatement(JCExpression clazz, int pos) {
+    JCExpression lambdaExpressionOrStatement(int pos, boolean hasArgs) {
         mode = EXPR;
         checkLambda();
+        int pos2 = S.pos();
+        if (S.token() == LBRACE) {
+            accept(LBRACE);
 
-        List<JCVariableDecl> args = List.nil();
-        if (S.token() == LPAREN) {
-            args = formalParameters(true);
-        }
+            List<JCVariableDecl> args = List.nil();
+            if (hasArgs) {
+                args = formalParameters(true);
+            }
 
-        S.pushState();
-        boolean isBlock = false;
-        accept(LBRACE);
-        if (S.token() == RBRACE) {
-            //empty block
-            isBlock = true;
+            S.pushState();
+            boolean isBlock = false;
+
+            if (S.token() == RBRACE) {
+                //empty block
+                isBlock = true;
+            }
+            else {
+                StatementKind sk = statementKind();
+                switch (sk) {
+                    case STATEMENT: isBlock = true; break;
+                    case EXPRESSION_STATEMENT:
+                    case EXPRESSION:
+                        parseExpression();
+                        isBlock = S.token() != RBRACE;
+                        break;
+                }
+            }
+            S.popState();
+
+            return isBlock ?
+                lambdaStatement(args, pos, pos2) :
+                lambdaExpression(args, pos);
         }
         else {
-            StatementKind sk = statementKind();
-            switch (sk) {
-                case STATEMENT: isBlock = true; break;
-                case EXPRESSION_STATEMENT:
-                case EXPRESSION:
-                    parseExpression();
-                    isBlock = S.token() != RBRACE;
-                    break;
-            }
+            return syntaxError("expected", LBRACE);
         }
-        S.popState();
-
-        return isBlock ?
-            lambdaStatement(clazz, args, pos) :
-            lambdaExpression(clazz, args, pos);
     }
 
-    JCExpression lambdaStatement(JCExpression clazz, List<JCVariableDecl> args, int pos) {
-        JCBlock block = block();
-        return toP(F.at(pos).Lambda(clazz, args, block));
+    JCExpression lambdaStatement(List<JCVariableDecl> args, int pos, int pos2) {
+        JCBlock block = block(pos2, 0, true);
+        accept(RBRACE);
+        return toP(F.at(pos).Lambda(args, block));
     }
 
-    JCExpression lambdaExpression(JCExpression clazz, List<JCVariableDecl> args, int pos) {
-        accept(LBRACE);
+    JCExpression lambdaExpression(List<JCVariableDecl> args, int pos) {
         JCTree expr = parseExpression();
         accept(RBRACE);
-        return toP(F.at(pos).Lambda(clazz, args, expr));
+        return toP(F.at(pos).Lambda(args, expr));
     }
 
     JCExpression functionType() {
@@ -1752,7 +1756,7 @@
         accept(HASH);
         return memberReferenceSuffix(pos1, t);
     }
-    
+
     JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
         checkMethodReferences();
         mode = EXPR;
@@ -1762,7 +1766,7 @@
         }
         t = toP(F.at(pos1).Select(t, ident()));
         int pos2 = S.pos();
-        if (S.token() == LPAREN) {            
+        if (S.token() == LPAREN) {
             List<JCExpression> types = methodParameterTypes();
             t = toP(F.at(pos2).Apply(typeArgs, t, types, true));
         }
@@ -1997,8 +2001,9 @@
 
     /** Block = "{" BlockStatements "}"
      */
-    JCBlock block(int pos, long flags) {
-        accept(LBRACE);
+    JCBlock block(int pos, long flags, boolean lambda) {
+        if (!lambda)
+            accept(LBRACE);
         List<JCStatement> stats = blockStatements();
         JCBlock t = F.at(pos).Block(flags, stats);
         while (S.token() == CASE || S.token() == DEFAULT) {
@@ -2008,12 +2013,17 @@
         // the Block node has a field "endpos" for first char of last token, which is
         // usually but not necessarily the last char of the last token.
         t.endpos = S.pos();
-        accept(RBRACE);
+        if (!lambda)
+            accept(RBRACE);
         return toP(t);
     }
 
+    JCBlock block(boolean lambda) {
+        return block(S.pos(), 0, lambda);
+    }
+
     public JCBlock block() {
-        return block(S.pos(), 0);
+        return block(false);
     }
 
     /** BlockStatements = { BlockStatement }
@@ -3126,7 +3136,7 @@
             } else if (S.token() == LBRACE && !isInterface &&
                        (mods.flags & Flags.StandardFlags & ~Flags.STATIC) == 0 &&
                        mods.annotations.isEmpty()) {
-                return List.<JCTree>of(block(pos, mods.flags));
+                return List.<JCTree>of(block(pos, mods.flags, false));
             } else {
                 pos = S.pos();
                 List<JCTypeParameter> typarams = typeParametersOpt();
@@ -3387,18 +3397,21 @@
         return formalParameters(false);
     }
 
-    List<JCVariableDecl> formalParameters(boolean optionalTypes) {
+    List<JCVariableDecl> formalParameters(boolean lambda) {
         ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>();
         JCVariableDecl lastParam = null;
-        accept(LPAREN);
-        if (S.token() != RPAREN) {
-            params.append(lastParam = formalParameter(optionalTypes));
+        if (!lambda) {
+            accept(LPAREN);
+        }
+        Token endOfArgs = lambda ? ARROW : RPAREN;
+        if (S.token() != endOfArgs) {
+            params.append(lastParam = formalParameter(lambda));
             while ((lastParam.mods.flags & Flags.VARARGS) == 0 && S.token() == COMMA) {
                 S.nextToken();
-                params.append(lastParam = formalParameter(optionalTypes));
+                params.append(lastParam = formalParameter(lambda));
             }
         }
-        accept(RPAREN);
+        accept(endOfArgs);
         return params.toList();
     }
 
@@ -3412,9 +3425,9 @@
     /** FormalParameter = { FINAL | '@' Annotation } Type VariableDeclaratorId
      *  LastFormalParameter = { FINAL | '@' Annotation } Type '...' Ident | FormalParameter
      */
-    JCVariableDecl formalParameter(boolean optionalTypes) {
+    JCVariableDecl formalParameter(boolean lambda) {
         JCModifiers mods = optFinal(Flags.PARAMETER);
-        if (optionalTypes) {
+        if (lambda) {
             S.pushState();
         }
         // need to distinguish between vararg annos and array annos
@@ -3423,9 +3436,9 @@
         JCExpression type = parseType();
         this.permitTypeAnnotationsPushBack = false;
 
-        if (optionalTypes && (
+        if (lambda && (
                 S.token() == COMMA ||
-                S.token() == RPAREN)) {
+                S.token() == ARROW)) {
             S.popState();
             return variableDeclaratorId(mods, null);
         }
--- a/src/share/classes/com/sun/tools/javac/parser/Token.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/parser/Token.java	Mon Oct 18 17:21:50 2010 +0100
@@ -111,6 +111,7 @@
     COMMA(","),
     DOT("."),
     HASH("#"),
+    ARROW("->"),
     ELLIPSIS("..."),
     EQ("="),
     GT(">"),
--- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Mon Oct 18 17:21:50 2010 +0100
@@ -1462,15 +1462,13 @@
         public JCTree body;
         public Symbol sym;
         public Type targetType;
-        public JCExpression clazz;
+        
         private boolean needsParameterInference = false;
     
         public JCLambda(List<JCVariableDecl> params,
-                        JCTree body,
-                        JCExpression clazz) {
+                        JCTree body) {
             this.params = params;
             this.body = body;
-            this.clazz = clazz;
             for (JCVariableDecl param : params) {
                 if (param.vartype == null) {
                     needsParameterInference = true;
@@ -1482,7 +1480,6 @@
         public int getTag() {
             return LAMBDA;
         }
-        public JCExpression getIdentifier() { return clazz; }
         @Override
         public void accept(Visitor v) {
             v.visitLambda(this);
--- a/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Mon Oct 18 17:21:50 2010 +0100
@@ -282,9 +282,8 @@
     public JCTree visitLambdaExpression(LambdaExpressionTree node, P p) {
         JCLambda t = (JCLambda) node;
         List<JCVariableDecl> params = copy(t.params, p);
-        JCExpression clazz = copy(t.clazz, p);
         JCTree body = copy(t.body, p);
-        return M.at(t.pos).Lambda(clazz, params, body);
+        return M.at(t.pos).Lambda(params, body);
     }
 
     public JCTree visitParenthesized(ParenthesizedTree node, P p) {
--- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Mon Oct 18 17:21:50 2010 +0100
@@ -686,6 +686,7 @@
      * Return true if the AST corresponds to a static select of the kind A.B
      */
     public static boolean isStaticSelector(JCTree base, Names names) {
+        if (base == null) return false;
         switch (base.getTag()) {
             case JCTree.IDENT: JCIdent id = (JCIdent)base;
                                return id.name != names._this &&
--- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Mon Oct 18 17:21:50 2010 +0100
@@ -367,11 +367,10 @@
         return tree;
     }
 
-    public JCLambda Lambda(JCExpression clazz,
-                           List<JCVariableDecl> params,
+    public JCLambda Lambda(List<JCVariableDecl> params,
                            JCTree body)
     {
-        JCLambda tree = new JCLambda(params, body, clazz);
+        JCLambda tree = new JCLambda(params, body);
         tree.pos = pos;
         return tree;
     }
--- a/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Mon Oct 18 17:21:50 2010 +0100
@@ -217,7 +217,6 @@
     }
 
     public void visitLambda(JCLambda tree) {
-        scan(tree.clazz);
         scan(tree.body);
         scan(tree.params);
     }
--- a/test/tools/javac/defender/Pos01.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/defender/Pos01.java	Mon Oct 18 17:21:50 2010 +0100
@@ -46,7 +46,7 @@
     public static void main(String[] args) {
        MyList<Integer> l = new MyList<Integer>();
        l.add(1); l.add(2); l.add(3);
-       l.map(#(Integer x){ x * x });
+       l.map(#{ Integer x -> x * x });
     }
 
     static <T> List<T> listMapper(List<T> l, Mapper<T> mapper) {
--- a/test/tools/javac/lambda/BadLambdaPos.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/BadLambdaPos.java	Mon Oct 18 17:21:50 2010 +0100
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @summary check that lambda is only allowed in plain argument position
+ * @summary check that lambda is only allowed in argument/cast/assignment context
  * @author  Maurizio Cimadamore
  * @compile/fail/ref=BadLambdaPos.out -XDrawDiagnostics BadLambdaPos.java
  */
@@ -34,5 +34,19 @@
 
 class Test {
     void test(Object x) {}
-    SAM test2() { test((Object)#(x){} ); }
+
+    void test1() {
+        test(#{ int x -> } + #{ int x -> } );
+        test(#{ int x -> } instanceof Object );
+    }
+
+    void test2() {
+        int i2 = #{ int x -> } + #{ int x -> };
+        boolean b = #{ int x -> } instanceof Object;
+    }
+
+    void test3() {
+        test((Object)#{ int x -> });
+        Object o = (Object)#{ int x -> };
+    }
 }
--- a/test/tools/javac/lambda/BadLambdaPos.out	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/BadLambdaPos.out	Mon Oct 18 17:21:50 2010 +0100
@@ -1,2 +1,11 @@
-BadLambdaPos.java:37:32: compiler.err.unexpected.lambda
-1 error
+BadLambdaPos.java:39:14: compiler.err.unexpected.lambda
+BadLambdaPos.java:39:30: compiler.err.unexpected.lambda
+BadLambdaPos.java:39:28: compiler.err.operator.cant.be.applied: +, #void(int),#void(int)
+BadLambdaPos.java:40:14: compiler.err.unexpected.lambda
+BadLambdaPos.java:44:18: compiler.err.unexpected.lambda
+BadLambdaPos.java:44:34: compiler.err.unexpected.lambda
+BadLambdaPos.java:44:32: compiler.err.operator.cant.be.applied: +, #void(int),#void(int)
+BadLambdaPos.java:45:21: compiler.err.unexpected.lambda
+BadLambdaPos.java:49:22: compiler.err.invalid.target.type.for.lambda.conv.1: java.lang.Object, (compiler.misc.target.for.lambda.conv.must.be.abstract: null, kindname.class, java.lang.Object)
+BadLambdaPos.java:50:28: compiler.err.invalid.target.type.for.lambda.conv.1: java.lang.Object, (compiler.misc.target.for.lambda.conv.must.be.abstract: null, kindname.class, java.lang.Object)
+10 errors
--- a/test/tools/javac/lambda/BadTargetType.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/BadTargetType.java	Mon Oct 18 17:21:50 2010 +0100
@@ -34,11 +34,11 @@
     static void m1(Object o) {}
     void m2(Object o) {}
 
-    static Object l1 = #(int pos) {};
-    Object l2 = #(int pos) {};
+    static Object l1 = #{ int pos -> };
+    Object l2 = #{ int pos -> };
 
     {
-        m1(#(int pos) {});
-        m2(#(int pos) {});
+        m1(#{ int pos -> });
+        m2(#{ int pos -> });
     }
 }
--- a/test/tools/javac/lambda/ExceptionTransparency01.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/ExceptionTransparency01.java	Mon Oct 18 17:21:50 2010 +0100
@@ -53,7 +53,7 @@
 
     static void test(final boolean cond) {
         try {
-            call(#() { if (cond) throw new A(); else throw new B();});
+            call(#{ if (cond) throw new A(); else throw new B();});
         }
         catch (final A|B ex) {
             CatchNumber catchNumber = ex.getClass().getAnnotation(CatchNumber.class);
--- a/test/tools/javac/lambda/ExceptionTransparency03.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/ExceptionTransparency03.java	Mon Oct 18 17:21:50 2010 +0100
@@ -40,8 +40,8 @@
     static abstract class IntSortableList extends AbstractList<Integer> implements SortableList<Integer> { }
 
     void test(IntSortableList isl) {
-        isl.forEach( Func<Integer,Integer, Exception> #( i ) { throw new Exception(); } );
-        isl.forEach(  #( i ) { throw new Exception(); } );
-        isl.<Exception>forEach( #( i ) { throw new Exception(); } );
+        isl.forEach((Func<Integer,Integer, Exception>)#{ i -> throw new Exception(); } );
+        isl.forEach(  #{ i -> throw new Exception(); } );
+        isl.<Exception>forEach( #{ i -> throw new Exception(); } );
     }
 }
--- a/test/tools/javac/lambda/LambdaCapture01.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaCapture01.java	Mon Oct 18 17:21:50 2010 +0100
@@ -56,7 +56,7 @@
     //Simple local capture
     void test1() {
         final int N = 1;
-        int x = LambdaCapture01.<Integer,Integer>exec(#(Integer x){x + N}, 3);
+        int x = LambdaCapture01.<Integer,Integer>exec(#{ Integer x -> x + N }, 3);
         assertTrue(4 == x);
     }
 
@@ -66,7 +66,7 @@
         new Tester() {
             public void test() {
                 final int M = 2;
-                int x = LambdaCapture01.<Integer,Integer>exec(#(Integer x){x + N + M}, 3);
+                int x = LambdaCapture01.<Integer,Integer>exec(#{ Integer x -> x + N + M }, 3);
                 assertTrue(6 == x);
             }
         }.test();
@@ -78,7 +78,7 @@
         class MyTester implements Tester {
             public void test() {
                 final int M = 2;
-                int x = LambdaCapture01.<Integer,Integer>exec(#(Integer x){x + N + M}, 3);
+                int x = LambdaCapture01.<Integer,Integer>exec(#{ Integer x -> x + N + M }, 3);
                 assertTrue(6 == x);
             }
         }
@@ -88,9 +88,9 @@
     //access to field from enclosing scope
     void test4() {
         final int N = 4;
-        int x1 = LambdaCapture01.<Integer,Integer>exec(#(Integer x){x + n + N}, 3);
+        int x1 = LambdaCapture01.<Integer,Integer>exec(#{ Integer x -> x + n + N }, 3);
         assertTrue(12 == x1);
-        int x2 = LambdaCapture01.<Integer,Integer>exec(#(Integer x){x + LambdaCapture01.this.n + N}, 3);
+        int x2 = LambdaCapture01.<Integer,Integer>exec(#{ Integer x -> x + LambdaCapture01.this.n + N }, 3);
         assertTrue(12 == x2);
     }
 
--- a/test/tools/javac/lambda/LambdaCapture02.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaCapture02.java	Mon Oct 18 17:21:50 2010 +0100
@@ -56,7 +56,7 @@
     //Simple local capture
     void test1() {
         final Integer N = 1;
-        int x = LambdaCapture02.<Integer,Integer>exec(#(Integer x){x + N}, 3);
+        int x = LambdaCapture02.<Integer,Integer>exec(#{ Integer x -> x + N }, 3);
         assertTrue(4 == x);
     }
 
@@ -66,7 +66,7 @@
         new Tester() {
             public void test() {
                 final Integer M = 2;
-                int x = LambdaCapture02.<Integer,Integer>exec(#(Integer x){x + N + M}, 3);
+                int x = LambdaCapture02.<Integer,Integer>exec(#{ Integer x -> x + N + M }, 3);
                 assertTrue(6 == x);
             }
         }.test();
@@ -78,7 +78,7 @@
         class MyTester implements Tester {
             public void test() {
                 final Integer M = 2;
-                int x = LambdaCapture02.<Integer,Integer>exec(#(Integer x){x + N + M}, 3);
+                int x = LambdaCapture02.<Integer,Integer>exec(#{ Integer x -> x + N + M }, 3);
                 assertTrue(6 == x);
             }
         }
@@ -88,9 +88,9 @@
     //access to field from enclosing scope
     void test4() {
         final Integer N = 4;
-        int x1 = LambdaCapture02.<Integer,Integer>exec(#(Integer x){x + n + N}, 3);
+        int x1 = LambdaCapture02.<Integer,Integer>exec(#{ Integer x -> x + n + N }, 3);
         assertTrue(12 == x1);
-        int x2 = LambdaCapture02.<Integer,Integer>exec(#(Integer x){x + LambdaCapture02.this.n + N}, 3);
+        int x2 = LambdaCapture02.<Integer,Integer>exec(#{ Integer x -> x + LambdaCapture02.this.n + N }, 3);
         assertTrue(12 == x2);
     }
 
--- a/test/tools/javac/lambda/LambdaCapture03.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaCapture03.java	Mon Oct 18 17:21:50 2010 +0100
@@ -61,7 +61,7 @@
                   class B {
                        void test() {
                            final Integer N3 = 3;
-                           int x = LambdaCapture03.exec(#(Integer x){x + n1 + n2 + N1 + N2 + N3}, 30);
+                           int x = LambdaCapture03.exec(#{ Integer x -> x + n1 + n2 + N1 + N2 + N3 }, 30);
                            assertTrue(x == 66);
                        }
                   }
@@ -80,7 +80,7 @@
                 new Tester() {
                     public void test() {
                         final Integer N3 = 3;
-                        int x = LambdaCapture03.exec(#(Integer x){x + n1 + n2 + N1 + N2 + N3}, 30);
+                        int x = LambdaCapture03.exec(#{ Integer x -> x + n1 + n2 + N1 + N2 + N3 }, 30);
                         assertTrue(x == 66);
                     }
                 }.test();
--- a/test/tools/javac/lambda/LambdaCapture04.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaCapture04.java	Mon Oct 18 17:21:50 2010 +0100
@@ -61,7 +61,7 @@
                   class B {
                        void test() {
                            final Integer N3 = 3;
-                           exec(#(final Integer x){new Tester() { public void test() { assertTrue(x + n1 + n2 + N1 + N2 + N3 == 66); } }.test()},30);
+                           exec(#{ final Integer x -> new Tester() { public void test() { assertTrue(x + n1 + n2 + N1 + N2 + N3 == 66); } }.test()},30);
                        }
                   }
                   new B().test();
@@ -79,7 +79,7 @@
                   class B {
                        void test() {
                            final Integer N3 = 3;
-                           exec(#(final Integer x){
+                           exec(#{ final Integer x ->
                                class LocTester implements Tester {
                                    public void test() { assertTrue(x + n1 + n2 + N1 + N2 + N3 == 66); }
                                };
@@ -101,7 +101,7 @@
                 new Tester() {
                     public void test() {
                         final Integer N3 = 3;
-                        exec(#(final Integer x){new Tester() { public void test() { assertTrue(x + n1 + n2 + N1 + N2 + N3 == 66); } }.test()},30);
+                        exec(#{ final Integer x -> new Tester() { public void test() { assertTrue(x + n1 + n2 + N1 + N2 + N3 == 66); } }.test()},30);
                     }
                 }.test();
             }
@@ -117,7 +117,7 @@
                 new Tester() {
                     public void test() {
                         final Integer N3 = 3;
-                        exec(#(final Integer x){
+                        exec(#{ final Integer x ->
                             class LocTester implements Tester {
                                 public void test() { assertTrue(x + n1 + n2 + N1 + N2 + N3 == 66); }
                             };
--- a/test/tools/javac/lambda/LambdaCapture05.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaCapture05.java	Mon Oct 18 17:21:50 2010 +0100
@@ -49,19 +49,19 @@
     int i = 40;
 
     void test1(final int a0) {
-        exec(#(final Integer a1){
-            final Integer x2 = 10; exec(#(final Integer a2) {
+        exec(#{ final Integer a1 ->
+            final Integer x2 = 10; exec(#{ final Integer a2 ->
                 final Integer x3 = 20;
-                exec(#(final Integer a3){assertTrue(106 == (a0 + a1 + a2 + a3 + x2 + x3 + i))},3);
+                exec(#{ final Integer a3 -> assertTrue(106 == (a0 + a1 + a2 + a3 + x2 + x3 + i))},3);
             },2);
         },1);
     }
 
     static void test2(final int a0) {
-        exec(#(final Integer a1){
-            final Integer x2 = 10; exec(#(final Integer a2) {
+        exec(#{ final Integer a1 ->
+            final Integer x2 = 10; exec(#{ final Integer a2 ->
                 final Integer x3 = 20;
-                exec(#(final Integer a3){assertTrue(66 == (a0 + a1 + a2 + a3 + x2 + x3))}, 3);
+                exec(#{ final Integer a3 -> assertTrue(66 == (a0 + a1 + a2 + a3 + x2 + x3))}, 3);
             }, 2);
         }, 1);
     }
--- a/test/tools/javac/lambda/LambdaConv01.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaConv01.java	Mon Oct 18 17:21:50 2010 +0100
@@ -64,14 +64,14 @@
         VoidToInt f1 = #{3};
         assertTrue(3 == f1.foo());
         //Covariant returns:
-        TU<Number, Integer> f2 = #(Integer x){x};
+        TU<Number, Integer> f2 = #{ Integer x -> x };
         assertTrue(3 == f2.foo(3));
         //Method resolution with boxing:
-        int x = LambdaConv01.<Integer,Integer>exec(#(Integer x){x}, 3);
+        int x = LambdaConv01.<Integer,Integer>exec(#{ Integer x -> x }, 3);
         assertTrue(3 == x);
         //Runtime exception transparency:
         try {
-            LambdaConv01.<Integer,Object>exec(#(Object x){x.hashCode()}, null);
+            LambdaConv01.<Integer,Object>exec(#{ Object x -> x.hashCode() }, null);
         }
         catch (RuntimeException e) {
             assertTrue(true);
@@ -83,14 +83,14 @@
         VoidToInt f1 = #{3};
         assertTrue(3 == f1.foo());
         //Covariant returns:
-        TU<Number, Integer> f2 = #(Integer x){x};
+        TU<Number, Integer> f2 = #{ Integer x -> x };
         assertTrue(3 == f2.foo(3));
         //Method resolution with boxing:
-        int x = LambdaConv01.<Integer,Integer>exec(#(Integer x){x}, 3);
+        int x = LambdaConv01.<Integer,Integer>exec(#{ Integer x -> x }, 3);
         assertTrue(3 == x);
         //Runtime exception transparency:
         try {
-            LambdaConv01.<Integer,Object>exec(#(Object x){x.hashCode()}, null);
+            LambdaConv01.<Integer,Object>exec(#{ Object x -> x.hashCode() }, null);
         }
         catch (RuntimeException e) {
             assertTrue(true);
@@ -102,14 +102,14 @@
         VoidToInt f1 = #{3};
         assertTrue(3 == f1.foo());
         //Covariant returns:
-        TU<Number, Integer> f2 = #(Integer x){x};
+        TU<Number, Integer> f2 = #{ Integer x -> x };
         assertTrue(3 == f2.foo(3));
         //Method resolution with boxing:
-        int x = LambdaConv01.<Integer,Integer>exec(#(Integer x){x}, 3);
+        int x = LambdaConv01.<Integer,Integer>exec(#{ Integer x -> x }, 3);
         assertTrue(3 == x);
         //Runtime exception transparency:
         try {
-            LambdaConv01.<Integer,Object>exec(#(Object x){x.hashCode()}, null);
+            LambdaConv01.<Integer,Object>exec(#{ Object x -> x.hashCode() }, null);
         }
         catch (RuntimeException e) {
             assertTrue(true);
@@ -121,14 +121,14 @@
         VoidToInt f1 = #{3};
         assertTrue(3 == f1.foo());
         //Covariant returns:
-        TU<Number, Integer> f2 = #(Integer x){x};
+        TU<Number, Integer> f2 = #{ Integer x -> x };
         assertTrue(3 == f2.foo(3));
         //Method resolution with boxing:
-        int x = LambdaConv01.<Integer,Integer>exec(#(Integer x){x}, 3);
+        int x = LambdaConv01.<Integer,Integer>exec(#{ Integer x -> x }, 3);
         assertTrue(3 == x);
         //Runtime exception transparency:
         try {
-            LambdaConv01.<Integer,Object>exec(#(Object x){x.hashCode()}, null);
+            LambdaConv01.<Integer,Object>exec(#{ Object x -> x.hashCode() }, null);
         }
         catch (RuntimeException e) {
             assertTrue(true);
--- a/test/tools/javac/lambda/LambdaConv02.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaConv02.java	Mon Oct 18 17:21:50 2010 +0100
@@ -39,12 +39,12 @@
     void test2(SAM s) {}
 
     static {
-        SAM s1 = #(){}; //error - no encl instance in scope
-        test1(#(){}); //error - no encl instance in scope
+        SAM s1 = #{}; //error - no encl instance in scope
+        test1(#{}); //error - no encl instance in scope
     }
 
     {
-        SAM s2 = #(){}; //ok
-        test2(#(){}); //ok
+        SAM s2 = #{}; //ok
+        test2(#{}); //ok
     }
 }
--- a/test/tools/javac/lambda/LambdaConv03.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaConv03.java	Mon Oct 18 17:21:50 2010 +0100
@@ -49,16 +49,16 @@
 
     static {
         //void
-        exec(#(Integer x){ assertTrue(x == 3); }, 3);
+        exec(#{ Integer x -> assertTrue(x == 3); }, 3);
         //Covariant returns:
-        int i = exec(#(Integer x){return x;}, 3);
+        int i = exec(#{ Integer x -> return x;}, 3);
         assertTrue(3 == i);
         //Method resolution with boxing:
-        int x = exec(#(Integer x){return x;}, 3);
+        int x = exec(#{ Integer x -> return x;}, 3);
         assertTrue(3 == x);
         //Runtime exception transparency:
         try {
-            exec(#(Object x){return x.hashCode();}, null);
+            exec(#{ Object x -> return x.hashCode();}, null);
         }
         catch (RuntimeException e) {
             assertTrue(true);
@@ -67,16 +67,16 @@
 
     {
         //void
-        exec(#(Integer x){ assertTrue(x == 3); }, 3);
+        exec(#{ Integer x -> assertTrue(x == 3); }, 3);
         //Covariant returns:
-        int i = exec(#(Integer x){return x;}, 3);
+        int i = exec(#{ Integer x -> return x;}, 3);
         assertTrue(3 == i);
         //Method resolution with boxing:
-        int x = exec(#(Integer x){return x;}, 3);
+        int x = exec(#{ Integer x -> return x;}, 3);
         assertTrue(3 == x);
         //Runtime exception transparency:
         try {
-            exec(#(Object x){return x.hashCode();}, null);
+            exec(#{ Object x -> return x.hashCode();}, null);
         }
         catch (RuntimeException e) {
             assertTrue(true);
@@ -85,16 +85,16 @@
 
     public static void test1() {
         //void
-        exec(#(Integer x){ assertTrue(x == 3); }, 3);
+        exec(#{ Integer x -> assertTrue(x == 3); }, 3);
         //Covariant returns:
-        int i = exec(#(Integer x){return x;}, 3);
+        int i = exec(#{ Integer x -> return x;}, 3);
         assertTrue(3 == i);
         //Method resolution with boxing:
-        int x = exec(#(Integer x){return x;}, 3);
+        int x = exec(#{ Integer x -> return x;}, 3);
         assertTrue(3 == x);
         //Runtime exception transparency:
         try {
-            exec(#(Object x){return x.hashCode();}, null);
+            exec(#{ Object x -> return x.hashCode();}, null);
         }
         catch (RuntimeException e) {
             assertTrue(true);
@@ -103,16 +103,16 @@
 
     public void test2() {
         //void
-        exec(#(Integer x){ assertTrue(x == 3); }, 3);
+        exec(#{ Integer x -> assertTrue(x == 3); }, 3);
         //Covariant returns:
-        int i = exec(#(Integer x){return x;}, 3);
+        int i = exec(#{ Integer x -> return x;}, 3);
         assertTrue(3 == i);
         //Method resolution with boxing:
-        int x = exec(#(Integer x){return x;}, 3);
+        int x = exec(#{ Integer x -> return x;}, 3);
         assertTrue(3 == x);
         //Runtime exception transparency:
         try {
-            exec(#(Object x){return x.hashCode();}, null);
+            exec(#{ Object x -> return x.hashCode();}, null);
         }
         catch (RuntimeException e) {
             assertTrue(true);
--- a/test/tools/javac/lambda/LambdaConv05.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaConv05.java	Mon Oct 18 17:21:50 2010 +0100
@@ -42,7 +42,7 @@
 
     void sort(List<String> data) {
       Collections.sort(data,
-                       #(String a, String b) { LambdaConv05.this.count++; return a.length()-b.length(); });
+                       #{ String a, String b -> LambdaConv05.this.count++; return a.length()-b.length(); });
     }
 
     public static void main(String[] args) {
--- a/test/tools/javac/lambda/LambdaConv06.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaConv06.java	Mon Oct 18 17:21:50 2010 +0100
@@ -32,7 +32,7 @@
 class LambdaConv06 {
 
     private int t() {
-        return a(#(final Object indexed) {
+        return a(#{ final Object indexed ->
             return b(new R() {
                 public String build(final Object index) {
                     return "";
--- a/test/tools/javac/lambda/LambdaConv07.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaConv07.java	Mon Oct 18 17:21:50 2010 +0100
@@ -44,22 +44,22 @@
 
 
     static {
-        SAM s = #(int i){assertTrue(i == 1)};
+        SAM s = #{ int i -> assertTrue(i == 1) };
         s.foo(1);
     }
 
     {
-        SAM s = #(int i){assertTrue(i == 2)};
+        SAM s = #{ int i -> assertTrue(i == 2) };
         s.foo(2);
     }
 
     static void test1() {
-        SAM s = #(int i){assertTrue(i == 3)};
+        SAM s = #{ int i -> assertTrue(i == 3) };
         s.foo(3);
     }
 
     void test2() {
-        SAM s = #(int i){assertTrue(i == 4)};
+        SAM s = #{ int i -> assertTrue(i == 4) };
         s.foo(4);
     }
 
--- a/test/tools/javac/lambda/LambdaConv08.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaConv08.java	Mon Oct 18 17:21:50 2010 +0100
@@ -26,6 +26,7 @@
  * @summary check that SAM conversion handles covarinat return types correctly
  * @author  Peter Levart
  * @author  Maurizio Cimadamore
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles LambdaConv08
  */
 
 public class LambdaConv08 {
--- a/test/tools/javac/lambda/LambdaConv09.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaConv09.java	Mon Oct 18 17:21:50 2010 +0100
@@ -66,11 +66,11 @@
     void test() {
         Foo1 f1 = #{};
         Foo2 f2 = #{};
-        Foo3 f3 = #(x) { true };
-        Bar3 b3 = #(x) { true };
-        Quux q = #(x) { true };
-        Foo4 f4 = #(x) { true };
-        Bar4<Integer> b4 = #(x, y) { 1 };
-        Comparator<Integer> c = #(x, y) { 1 };
+        Foo3 f3 = #{ x -> true };
+        Bar3 b3 = #{ x -> true };
+        Quux q = #{ x -> true };
+        Foo4 f4 = #{ x -> true };
+        Bar4<Integer> b4 = #{ x, y -> 1 };
+        Comparator<Integer> c = #{ x, y ->  1 };
     }
 }
--- a/test/tools/javac/lambda/LambdaConv10.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaConv10.java	Mon Oct 18 17:21:50 2010 +0100
@@ -33,6 +33,6 @@
     interface Method1<R, A1, throws E> { public R call( A1 a1 ) throws E; }
 
     public static void main( final String... notUsed ) throws Throwable {
-        Method1<Integer,Integer,void> m1 = #( int i ) { 2 * i };
+        Method1<Integer,Integer,void> m1 = #{ int i -> 2 * i };
     }
 }
--- a/test/tools/javac/lambda/LambdaConversionTest.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaConversionTest.java	Mon Oct 18 17:21:50 2010 +0100
@@ -137,7 +137,7 @@
 
     static String formClient(PackageKind samPkg) {
         String clientTemplate = "class Client { \n" +
-                " void test() { Sam s = #(String s){}; } \n }";
+                " void test() { Sam s = #{ String s -> }; } \n }";
         return  samPkg.getImportStat() + "\n" +
                 clientTemplate;
     }
--- a/test/tools/javac/lambda/LambdaExpr01.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaExpr01.java	Mon Oct 18 17:21:50 2010 +0100
@@ -68,13 +68,13 @@
         assertTrue(3 == s_i.m());
         S_Integer s_I = #{3};
         assertTrue(3 == s_I.m());
-        S_int_int s_i_i = #(int x){ x + 1 };
+        S_int_int s_i_i = #{ int x -> x + 1 };
         assertTrue(4 == s_i_i.m(3));
-        S_int_Integer s_i_I = #(int x){ x + 1 };
+        S_int_Integer s_i_I = #{ int x -> x + 1 };
         assertTrue(4 == s_i_I.m(3));
-        S_Integer_int s_I_i = #(Integer x){ x.intValue() + 1 };
+        S_Integer_int s_I_i = #{ Integer x -> x.intValue() + 1 };
         assertTrue(4 == s_I_i.m(3));
-        S_Integer_Integer s_I_I = #(Integer x){ x.intValue() + 1 };
+        S_Integer_Integer s_I_I = #{ Integer x -> x.intValue() + 1 };
         assertTrue(4 == s_I_I.m(3));
     }
 
@@ -83,13 +83,13 @@
         assertTrue(3 == s_i.m());
         S_Integer s_I = #{3};
         assertTrue(3 == s_I.m());
-        S_int_int s_i_i = #(int x){ x + 1 };
+        S_int_int s_i_i = #{ int x -> x + 1 };
         assertTrue(4 == s_i_i.m(3));
-        S_int_Integer s_i_I = #(int x){ x + 1 };
+        S_int_Integer s_i_I = #{ int x -> x + 1 };
         assertTrue(4 == s_i_I.m(3));
-        S_Integer_int s_I_i = #(Integer x){ x.intValue() + 1 };
+        S_Integer_int s_I_i = #{ Integer x -> x.intValue() + 1 };
         assertTrue(4 == s_I_i.m(3));
-        S_Integer_Integer s_I_I = #(Integer x){ x.intValue() + 1 };
+        S_Integer_Integer s_I_I = #{ Integer x -> x.intValue() + 1 };
         assertTrue(4 == s_I_I.m(3));
     }
 
@@ -98,13 +98,13 @@
         assertTrue(3 == s_i.m());
         S_Integer s_I = #{3};
         assertTrue(3 == s_I.m());
-        S_int_int s_i_i = #(int x){ x + 1 };
+        S_int_int s_i_i = #{ int x -> x + 1 };
         assertTrue(4 == s_i_i.m(3));
-        S_int_Integer s_i_I = #(int x){ x + 1 };
+        S_int_Integer s_i_I = #{ int x -> x + 1 };
         assertTrue(4 == s_i_I.m(3));
-        S_Integer_int s_I_i = #(Integer x){ x.intValue() + 1 };
+        S_Integer_int s_I_i = #{ Integer x -> x.intValue() + 1 };
         assertTrue(4 == s_I_i.m(3));
-        S_Integer_Integer s_I_I = #(Integer x){ x.intValue() + 1 };
+        S_Integer_Integer s_I_I = #{ Integer x -> x.intValue() + 1 };
         assertTrue(4 == s_I_I.m(3));
     }
 
@@ -113,13 +113,13 @@
         assertTrue(3 == s_i.m());
         S_Integer s_I = #{3};
         assertTrue(3 == s_I.m());
-        S_int_int s_i_i = #(int x){ x + 1 };
+        S_int_int s_i_i = #{ int x -> x + 1 };
         assertTrue(4 == s_i_i.m(3));
-        S_int_Integer s_i_I = #(int x){ x + 1 };
+        S_int_Integer s_i_I = #{ int x -> x + 1 };
         assertTrue(4 == s_i_I.m(3));
-        S_Integer_int s_I_i = #(Integer x){ x.intValue() + 1 };
+        S_Integer_int s_I_i = #{ Integer x -> x.intValue() + 1 };
         assertTrue(4 == s_I_i.m(3));
-        S_Integer_Integer s_I_I = #(Integer x){ x.intValue() + 1 };
+        S_Integer_Integer s_I_I = #{ Integer x -> x.intValue() + 1 };
         assertTrue(4 == s_I_I.m(3));
     }
 
--- a/test/tools/javac/lambda/LambdaExpr02.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaExpr02.java	Mon Oct 18 17:21:50 2010 +0100
@@ -64,62 +64,62 @@
     }
 
     static {
-        S_int s_i = #(){ return 3; };
+        S_int s_i = #{ return 3; };
         assertTrue(3 == s_i.m());
-        S_Integer s_I = #(){ return 3; };
+        S_Integer s_I = #{ return 3; };
         assertTrue(3 == s_I.m());
-        S_int_int s_i_i = #(int x){ return x + 1; };
+        S_int_int s_i_i = #{ int x -> return x + 1; };
         assertTrue(4 == s_i_i.m(3));
-        S_int_Integer s_i_I = #(int x){ return x + 1; };
+        S_int_Integer s_i_I = #{ int x -> return x + 1; };
         assertTrue(4 == s_i_I.m(3));
-        S_Integer_int s_I_i = #(Integer x){ return x.intValue() + 1; };
+        S_Integer_int s_I_i = #{ Integer x -> return x.intValue() + 1; };
         assertTrue(4 == s_I_i.m(3));
-        S_Integer_Integer s_I_I = #(Integer x) { return x.intValue() + 1; };
+        S_Integer_Integer s_I_I = #{ Integer x -> return x.intValue() + 1; };
         assertTrue(4 == s_I_I.m(3));
     }
 
     {
-        S_int s_i = #(){ return 3; };
+        S_int s_i = #{ return 3; };
         assertTrue(3 == s_i.m());
-        S_Integer s_I = #(){ return 3; };
+        S_Integer s_I = #{ return 3; };
         assertTrue(3 == s_I.m());
-        S_int_int s_i_i = #(int x){ return x + 1; };
+        S_int_int s_i_i = #{ int x -> return x + 1; };
         assertTrue(4 == s_i_i.m(3));
-        S_int_Integer s_i_I = #(int x){ return x + 1; };
+        S_int_Integer s_i_I = #{ int x -> return x + 1; };
         assertTrue(4 == s_i_I.m(3));
-        S_Integer_int s_I_i = #(Integer x){ return x.intValue() + 1; };
+        S_Integer_int s_I_i = #{ Integer x -> return x.intValue() + 1; };
         assertTrue(4 == s_I_i.m(3));
-        S_Integer_Integer s_I_I = #(Integer x) { return x.intValue() + 1; };
+        S_Integer_Integer s_I_I = #{ Integer x -> return x.intValue() + 1; };
         assertTrue(4 == s_I_I.m(3));
     }
 
     static void test1() {
-        S_int s_i = #(){ return 3; };
+        S_int s_i = #{ return 3; };
         assertTrue(3 == s_i.m());
-        S_Integer s_I = #(){ return 3; };
+        S_Integer s_I = #{ return 3; };
         assertTrue(3 == s_I.m());
-        S_int_int s_i_i = #(int x){ return x + 1; };
+        S_int_int s_i_i = #{ int x -> return x + 1; };
         assertTrue(4 == s_i_i.m(3));
-        S_int_Integer s_i_I = #(int x){ return x + 1; };
+        S_int_Integer s_i_I = #{ int x -> return x + 1; };
         assertTrue(4 == s_i_I.m(3));
-        S_Integer_int s_I_i = #(Integer x){ return x.intValue() + 1; };
+        S_Integer_int s_I_i = #{ Integer x -> return x.intValue() + 1; };
         assertTrue(4 == s_I_i.m(3));
-        S_Integer_Integer s_I_I = #(Integer x) { return x.intValue() + 1; };
+        S_Integer_Integer s_I_I = #{ Integer x -> return x.intValue() + 1; };
         assertTrue(4 == s_I_I.m(3));
     }
 
     void test2() {
-        S_int s_i = #(){ return 3; };
+        S_int s_i = #{ return 3; };
         assertTrue(3 == s_i.m());
-        S_Integer s_I = #(){ return 3; };
+        S_Integer s_I = #{ return 3; };
         assertTrue(3 == s_I.m());
-        S_int_int s_i_i = #(int x){ return x + 1; };
+        S_int_int s_i_i = #{ int x -> return x + 1; };
         assertTrue(4 == s_i_i.m(3));
-        S_int_Integer s_i_I = #(int x){ return x + 1; };
+        S_int_Integer s_i_I = #{ int x -> return x + 1; };
         assertTrue(4 == s_i_I.m(3));
-        S_Integer_int s_I_i = #(Integer x){ return x.intValue() + 1; };
+        S_Integer_int s_I_i = #{ Integer x -> return x.intValue() + 1; };
         assertTrue(4 == s_I_i.m(3));
-        S_Integer_Integer s_I_I = #(Integer x) { return x.intValue() + 1; };
+        S_Integer_Integer s_I_I = #{ Integer x -> return x.intValue() + 1; };
         assertTrue(4 == s_I_I.m(3));
     }
 
--- a/test/tools/javac/lambda/LambdaExpr04.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaExpr04.java	Mon Oct 18 17:21:50 2010 +0100
@@ -34,11 +34,11 @@
     interface SAM {
         void m(int i);
     }
-    static SAM lambda_01 = #(int pos) {};
+    static SAM lambda_01 = #{ int pos -> };
 
-    static final SAM lambda_02 = #(int pos) {};
+    static final SAM lambda_02 = #{ int pos -> };
 
-    SAM lambda_03 = #(int pos) {};
+    SAM lambda_03 = #{ int pos -> };
 
-    final SAM lambda_04 = #(int pos) {};
+    final SAM lambda_04 = #{ int pos -> };
 }
--- a/test/tools/javac/lambda/LambdaExpr05.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaExpr05.java	Mon Oct 18 17:21:50 2010 +0100
@@ -32,6 +32,6 @@
 
     interface SAM { int foo(int i); }
 
-    SAM s1 = #(i) { i * 2 };
-    SAM s2 = #(i) { 2 * i };
+    SAM s1 = #{i -> i * 2 };
+    SAM s2 = #{i -> 2 * i };
 }
--- a/test/tools/javac/lambda/LambdaExprNotVoid.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaExprNotVoid.java	Mon Oct 18 17:21:50 2010 +0100
@@ -32,6 +32,6 @@
 
     interface SAM { void foo(int i); }
 
-    SAM s1 = #(i) { i * 2 };
-    SAM s2 = #(i) { 2 * i };
+    SAM s1 = #{ i -> i * 2 };
+    SAM s2 = #{ i -> 2 * i };
 }
--- a/test/tools/javac/lambda/LambdaExprNotVoid.out	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaExprNotVoid.out	Mon Oct 18 17:21:50 2010 +0100
@@ -1,3 +1,3 @@
-LambdaExprNotVoid.java:35:23: compiler.err.prob.found.req: (compiler.misc.incompatible.types), int, void
-LambdaExprNotVoid.java:36:23: compiler.err.prob.found.req: (compiler.misc.incompatible.types), int, void
+LambdaExprNotVoid.java:35:24: compiler.err.prob.found.req: (compiler.misc.incompatible.types), int, void
+LambdaExprNotVoid.java:36:24: compiler.err.prob.found.req: (compiler.misc.incompatible.types), int, void
 2 errors
--- a/test/tools/javac/lambda/LambdaScope01.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaScope01.java	Mon Oct 18 17:21:50 2010 +0100
@@ -54,13 +54,17 @@
     }
 
     public void test1() {
-        int x = LambdaScope01.<Integer,Integer>exec(#(Integer x){ x * hashCode() }, 3);
-        assertTrue(true); //should not throw
+        try {
+            int x = LambdaScope01.<Integer,Integer>exec(#{ Integer x -> x * hashCode() }, 3);
+        }
+        catch (RuntimeException e) {
+            assertTrue(true); //should throw
+        }
     }
 
     public void test2() {
         final int n = 10;
-        int x = LambdaScope01.<Integer,Integer>exec(#(Integer x){ x + n }, 3);
+        int x = LambdaScope01.<Integer,Integer>exec(#{ Integer x -> x + n }, 3);
         assertTrue(13 == x);
     }
 
--- a/test/tools/javac/lambda/LambdaScope02.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/LambdaScope02.java	Mon Oct 18 17:21:50 2010 +0100
@@ -38,29 +38,28 @@
             throw new AssertionError();
     }
 
+    @Override
+    public String toString() {
+        return "Callable1";
+    }
+
     static abstract class Callable {
         abstract void call();
         @Override
         public String toString() {
-            return "Callable";
+            return "Callable2";
         }
     }
 
     static void call(Callable c) { c.call(); }
-
-    static void test1() {
-        call(#() {assertTrue(this.toString().equals("Callable"));});
-        call(#() {assertTrue(toString().equals("Callable"));});
-    }
-
-    void test2() {
-        call(#() {assertTrue(this.toString().equals("Callable"));});
-        call(#() {assertTrue(toString().equals("Callable"));});
+    
+    void test() {
+        call(#{ assertTrue(LambdaScope02.this.toString().equals("Callable1")); });
+        call(#{ assertTrue(toString().equals("Callable1")); });
     }
 
     public static void main(String[] args) {
-        test1();
-        new LambdaScope02().test2();
-        assertTrue(assertionCount == 4);
+        new LambdaScope02().test();
+        assertTrue(assertionCount == 2);
     }
 }
--- a/test/tools/javac/lambda/MethodReference07.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/MethodReference07.java	Mon Oct 18 17:21:50 2010 +0100
@@ -37,7 +37,7 @@
        String getX() { return null; }
 
        static void test() {
-          SAM s = Foo<String>#getX();
+          SAM s = Foo<String>.#getX();
        }
     }
 }
--- a/test/tools/javac/lambda/MethodReference12.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/MethodReference12.java	Mon Oct 18 17:21:50 2010 +0100
@@ -39,7 +39,7 @@
     public static void main(String[] args) {
         try {
             test(MethodReference12#print(int));
-            test(#(i) { System.out.println(i); } );
+            test(#{ i -> System.out.println(i); } );
         }
         catch (Throwable t) {
             t.printStackTrace();
--- a/test/tools/javac/lambda/NakedThis.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/NakedThis.java	Mon Oct 18 17:21:50 2010 +0100
@@ -26,19 +26,15 @@
  * @summary basic test for capture of non-mutable locals
  * @author  Brian Goetz
  * @author  Maurizio Cimadamore
- * @compile -XDrawDiagnostics NakedThis.java
+ * @compile NakedThis.java
  */
 
 class NakedThis {
 
-    interface SAM1 {
-        SAM1 m(int x);
-    }
-
-    interface SAM2 {
+    interface SAM {
         NakedThis m(int x);
     }
   
-    SAM1 s1 = #(int x){ this };
-    SAM2 s2 = #(int x){ NakedThis.this };
+    SAM s1 = #{ int x -> this };
+    SAM s2 = #{ int x -> NakedThis.this };
 }
--- a/test/tools/javac/lambda/TargetType01.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType01.java	Mon Oct 18 17:21:50 2010 +0100
@@ -42,6 +42,6 @@
 
     static {
         //ambiguity here - the compiler does not try all the combinations!
-        M(#(final x1){return M(#(x2) { return x1 + x2; });});
+        M(#{ final x1 -> return M(#{ x2 -> return x1 + x2; });});
     }
 }
--- a/test/tools/javac/lambda/TargetType01.out	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType01.out	Mon Oct 18 17:21:50 2010 +0100
@@ -1,2 +1,2 @@
-TargetType01.java:45:30: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01
+TargetType01.java:45:33: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01
 1 error
--- a/test/tools/javac/lambda/TargetType02.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType02.java	Mon Oct 18 17:21:50 2010 +0100
@@ -40,19 +40,21 @@
 
     static abstract class S1<X extends Number> {
         abstract X m(Integer x);
-        public String toString() { assertTrue(true); return super.toString(); }
     }
 
     static abstract class S2<X extends String> {
         abstract X m(Integer x);
-        public String toString() { assertTrue(false); return super.toString(); }
     }
 
-    static <Z extends Number> void call(S1<Z> s) { s.m(1); }
-    static <Z extends String> void call(S2<Z> s) { s.m(2); }
+    static <Z extends Number> void call(S1<Z> s) { s.m(1); assertTrue(true); }
+    static <Z extends String> void call(S2<Z> s) { s.m(2); assertTrue(false); }
+
+    void test() {
+        call(#{ i -> toString(); return i; });
+    }
 
     public static void main(String[] args) {
-        call(#(i) { toString(); return i; });
+        new TargetType02().test();
         assertTrue(assertionCount == 1);
     }
 }
--- a/test/tools/javac/lambda/TargetType03.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType03.java	Mon Oct 18 17:21:50 2010 +0100
@@ -52,7 +52,7 @@
         numbers.add(3);
         numbers.add(4);
         numbers.add(5);
-        List<Integer> sqNumbers = numbers.map(#(a){ a * a });
+        List<Integer> sqNumbers = numbers.map(#{ a -> a * a });
         //check invariants
         if (numbers.size() != sqNumbers.size()) {
             throw new AssertionError();
--- a/test/tools/javac/lambda/TargetType04.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType04.java	Mon Oct 18 17:21:50 2010 +0100
@@ -33,7 +33,7 @@
        Y m(X x);
     }
 
-    S<Integer, Integer> s1 = #(i) { return i; }; //ok
-    S<Double, Integer> s2 = #(i) { return i; }; //no
-    S<Integer, Double> s3 = #(i) { return i; }; //no
+    S<Integer, Integer> s1 = #{ i -> return i; }; //ok
+    S<Double, Integer> s2 = #{ i -> return i; }; //no
+    S<Integer, Double> s3 = #{ i -> return i; }; //no
 }
--- a/test/tools/javac/lambda/TargetType04.out	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType04.out	Mon Oct 18 17:21:50 2010 +0100
@@ -1,3 +1,3 @@
-TargetType04.java:37:43: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Double, java.lang.Integer
-TargetType04.java:38:43: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Integer, java.lang.Double
+TargetType04.java:37:44: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Double, java.lang.Integer
+TargetType04.java:38:44: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Integer, java.lang.Double
 2 errors
--- a/test/tools/javac/lambda/TargetType05.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType05.java	Mon Oct 18 17:21:50 2010 +0100
@@ -41,14 +41,9 @@
         R call(A a);
     }
 
-    static int doFactorial(Func<Integer, Integer> fact, int i) {
-        return fact.call(i);
-    }
-
     public static void main(String[] args) {
-        Func<Integer, Integer> f = #(i) { return i == 1 ? 1 : call(i-1) * i; };
+        Func<Integer, Integer> f = #{ i -> return i == 1 ? 1 : f.call(i-1) * i; };
         assertTrue(f.call(5) == 120);
-        assertTrue(doFactorial(#(i) { return i == 1 ? 1 : call(i-1) * i; }, 5) == 120);
-        assertTrue(assertionCount == 2);
+        assertTrue(assertionCount == 1);
     }
 }
--- a/test/tools/javac/lambda/TargetType06.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType06.java	Mon Oct 18 17:21:50 2010 +0100
@@ -43,6 +43,6 @@
     static <B> List<B> map(Function<B, B> function) { return null; }
 
     void test() {
-        List<Foo> l = map(#(foo){ foo.getFoo() });
+        List<Foo> l = map(#{ foo -> foo.getFoo() });
     }
 }
--- a/test/tools/javac/lambda/TargetType07.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType07.java	Mon Oct 18 17:21:50 2010 +0100
@@ -38,6 +38,6 @@
     public static <X> void call(SAM2<X> s) { }
 
     public static void main(String[] args) {
-        call(SAM1<Integer> #{ 1 });
+        call((SAM1<Integer>)#{ 1 });
     }
 }
--- a/test/tools/javac/lambda/TargetType08.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType08.java	Mon Oct 18 17:21:50 2010 +0100
@@ -38,6 +38,6 @@
     public static void call(SAM2 s) { }
 
     public static void main(String[] args) {
-        call(SAM1 #{ "Hello!" });
+        call((SAM1)#{ "Hello!" });
     }
 }
--- a/test/tools/javac/lambda/TargetType10.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType10.java	Mon Oct 18 17:21:50 2010 +0100
@@ -35,6 +35,6 @@
 
     static class Test {
         <A,B,C> Function<A,C> compose(Function<B,C> g, Function<A,? extends B> f) { return null; }
-        { compose(#(x){ "a" + x }, #(x){ x + "b" }); }
+        { compose(#{ x ->  "a" + x }, #{ x -> x + "b" }); }
     }
 }
--- a/test/tools/javac/lambda/TargetType11.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType11.java	Mon Oct 18 17:21:50 2010 +0100
@@ -37,7 +37,7 @@
         public <T> Predicate<T> and(Predicate<? super T>... first) { return null; }
         public Predicate<Character> forPredicate(Predicate<? super Character> predicate) { return null; }
         
-        Predicate<Character> c2 = forPredicate(#(c){c.compareTo('e') < 0});
-        Predicate<Integer> k = and(#(i){i > 0}, #(i){i % 2 == 0});
+        Predicate<Character> c2 = forPredicate(#{ c -> c.compareTo('e') < 0 });
+        Predicate<Integer> k = and(#{ i -> i > 0 }, #{ i -> i % 2 == 0 });
     }
 }
--- a/test/tools/javac/lambda/TargetType12.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType12.java	Mon Oct 18 17:21:50 2010 +0100
@@ -37,7 +37,7 @@
     }
 
     static <T, U extends Comparable<? super U>> void sortBy2(T[] array, Extractor<T, U> extractor) {
-        Comparator<T> comparator = #(left,right){extractor.get(left).compareTo(extractor.get(right)) };
+        Comparator<T> comparator = #{ left,right -> extractor.get(left).compareTo(extractor.get(right)) };
         Arrays.sort(array, comparator);
     }
 }
--- a/test/tools/javac/lambda/TargetType13.java	Sat Sep 18 15:03:28 2010 -0700
+++ b/test/tools/javac/lambda/TargetType13.java	Mon Oct 18 17:21:50 2010 +0100
@@ -37,6 +37,6 @@
     static <throws E> void call(SAM<E> s) throws E { }
 
     void test() {
-        call(#(i) { if (i == 2) throw new Exception(); return; });
+        call(#{ i -> if (i == 2) throw new Exception(); return; });
     }
 }