Convert Lambda Expressions From C# To Java Using CodePorting Engine
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   zarfishan
Posted On:   Wednesday, May 30, 2012 10:10 PM

    CodePorting is one of few sites which is always trying to make it easier for developers to translate their C# Apps to java instantly by adding more and more language constructs in their CodePorting C#2Java Engine.  To keep this persistent nature, they have recently added support for Lambda Expressions in CodePorting Engine.  Anyone of you who don’t know what Lambda Expressions are let me explain them to you in short. Lambda Expressions are unspecified methods in C# which provide brief and functional syntax. But in java there is no alternative for Lambda Expression, so from now on CodePorting C#2Java eng   More>>

 

 

CodePorting is one of few sites which is always trying to make it easier for developers to translate their C# Apps to java instantly by adding more and more language constructs in their CodePorting C#2Java Engine.  To keep this persistent nature, they have recently added support for Lambda Expressions in CodePorting Engine.  Anyone of you who don’t know what Lambda Expressions are let me explain them to you in short. Lambda Expressions are unspecified methods in C# which provide brief and functional syntax. But in java there is no alternative for Lambda Expression, so from now on CodePorting C#2Java engine will intelligently handle these kinds of expressions by producing the auto generated code.

See the following Code Example to see how CodePorting handles converting Lambda Expressions while converting from C# to Java:

C# Code:

 

using System ;

using System .Collections.Generic;

using System .Linq;

using System .Text;

 

namespace CSharp2Java.Samples.Convert.LambdaExpressions

{

    public static class LambdaSample

    {

        delegate int del( int u);

        static void Main(string[] args)

        {

            del myDelegate = b => b * b + b;

            del mydel2 = x => x * x * x - x;

            int j = myDelegate(5); //j = 25

            int y = mydel2(5); //y = 125

        }

    }

}

 

Java Code:

 

package CSharp2Java.Samples.Convert.LambdaExpressions;

 

// ********* THIS FILE IS AUTO PORTED FORM C# USING CODEPORTING.COM *********

public class LambdaSample

{

    interface del{

          int invoke( int u);

}

    static void main( String [] args)

    {

        del myDelegate = new del() {

public int invoke( int b) {

     return   b * b + b;

}};

        del mydel2 = new del() {

public int invoke( int x) {

    return   x * x * x - x;

}};

        int j = myDelegate.invoke(5); //j = 25

        int y = mydel2.invoke(5); //y = 125

    }

}

 

From the above example it is clear that CodePorting Engine created interface classes to handle Lambda Expression.

   <<Less
About | Sitemap | Contact