B4J Question Java version and Lambda Expressions

Discussion in 'B4J Questions' started by Roycefer, Jun 28, 2015.

  1. Roycefer

    Roycefer Well-Known Member Licensed User

    Using lambda expressions in inline Java code results in the following compile-time error:
    B4J version: 3.02
    Parsing code.    (
    Compiling code.    (
    Compiling generated Java code.    Error
    B4J line: 
    End Sub
    125: error: lambda expressions are not supported in -source 1.5
        Calc c1 = (a,b)->{System.out.println(a + 
    "+" + b); return a+b;};
      (use -source 8 or higher to enable lambda expressions)
    1 error
    As you can see, I'm using Java 8 Update 40. Why is inline Java code being compiled using "-source 1.5"?
  2. Erel

    Erel Administrator Staff Member Licensed User

    It will be changed in the future.
    Roycefer likes this.
  3. wl

    wl Well-Known Member Licensed User

    Which brings me to the following question ...

    why not implement Lambda expressions directly into B4X ?
  4. Roycefer

    Roycefer Well-Known Member Licensed User

    As far as I know, Android is still stuck at the Java 7 language level, which doesn't support lambda expressions. Objective C uses blocks, instead of lambdas. It wouldn't be possible to just simply provide a wrapper for Java 8-style lambdas. I suspect Erel would have to build in lambda support at the B4X language level and then implement it separately for each of the three parsers. This sounds like a huge project for such a specialized function. I suspect inheritance is probably a much higher priority in B4X language development and even that's probably decades away.

    However, the precursor to lambda expressions, function objects, could be hacked together by B4X programmers today with the language as it now stands. The CallSub() function gives us a lot of power.
  5. wl

    wl Well-Known Member Licensed User


    Indeed I agree in such a situation it would need lots of work.

    The CallSub() is indeed powerful but as it is not strongly typed may introduce a lot of mayhem... I would rather like to have real "function pointers" / delegates or whatever you would call them.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice