Fork me on GitHub

Home Forums JSweet Discussion Java lamba and method reference

This topic contains 2 replies, has 2 voices, and was last updated by Avatar Anonymous 1 year, 3 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3388
    Avatar
    Anonymous

    Hi,

    I am experimenting with JSweet and try to transpile the following code:

    
    public interface MyFunct {
    
        MyFunct SUM2 = new MyFunct() {
            @Override
            public double combine(double a, double b) {
                return a + b;
            }
        };
        MyFunct SUM = (a, b) -> a + b;
        MyFunct MAX = Math::max;
    
        double combine(double a, double b);
    }
    

    The SUM2 only version transpiles fine.

    Code having only SUM gives:

    > Task :jsweet FAILED
    internal transpiler error at /Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyFunct.java(9)
    dumping transpiler’s strack trace:
    [JCVariableDecl] MyFunct SUM = (a,b)->a + … (/Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyFunct.java:9)
    [JCClassDecl] public interface MyFunct {… (/Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyFunct.java:6)
    [JCCompilationUnit] package quickstart;… (/Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyFunct.java:1)
    java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$VarSymbol cannot be cast to com.sun.tools.javac.code.Symbol$MethodSymbol
    at org.jsweet.transpiler.Java2TypeScriptTranslator.substituteAssignedExpression(Java2TypeScriptTranslator.java:5639)
    at org.jsweet.transpiler.Java2TypeScriptTranslator.visitVarDef(Java2TypeScriptTranslator.java:3265)

    According to JSweet FAQ lambda is supposed to work. What am I missing here?

    Code having only MAX gives:

    > Task :jsweet FAILED
    type ‘(arg0: any, arg1: any) => number’ is not assignable to type ‘MyFunct’ at /Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyFunct.java(8)

    What about methode references?

    Thanks!

    #3390
    Avatar
    Anonymous

    Hi,

    Has anyone idea how these problems can be resolved?

    Thanks!

    #3416
    Avatar
    Anonymous

    Eric’s shoulders relaxed as he dissertation writing service review entered the space between the two buildings. He didn’t mind the rotten pumpkin beside the half-open dumpster or the droplets from above of water mixed with god knows what. For a moment or two, he could hide from this city, and that was worth the stench. He took a deep breath as he reentered civilization and sunlight, yanking open the door to the diner before slamming it shut behind him.

Viewing 3 posts - 1 through 3 (of 3 total)

The forum ‘JSweet Discussion’ is closed to new topics and replies.