Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Convert Lambda Expressions From C# To Java Using CodePorting Engine (http://www.go4expert.com/forums/convert-lambda-expressions-c-sharp-java-t28516/)

zarfishan 4Jun2012 12:39

Convert Lambda Expressions From C# To Java Using CodePorting Engine
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.

All times are GMT +5.5. The time now is 04:16.