1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Convert Lambda Expressions From C# To Java Using CodePorting Engine

Discussion in 'Java' started by zarfishan, Jun 4, 2012.

  1. zarfishan

    zarfishan New Member

    Jun 4, 2012
    Likes Received:
    Trophy Points:
    CodePorting.com 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 Expression is let me explain it 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;
    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.
    Last edited by a moderator: Jun 4, 2012

Share This Page