Convert Lambda Expressions From C# To Java Using CodePorting Engine

Submitted By: codeporting
Date: Wednesday, May 30, 2012
Rating: (Not rated) (Rate It)
Share: Share By Email By Email

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 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;

// ********* 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.

Comments (0)


Add Your Rating

(Not published)
star
starstar
starstarstar
starstarstarstar
starstarstarstarstar
 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.