Java 8 Lambda Syntax has been (mostly) Finalized

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 20077 Views - Last Post: 15 September 2011 - 07:20 AM Rate Topic: -----

#1 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4479
  • View blog
  • Posts: 7,801
  • Joined: 08-June 10

Java 8 Lambda Syntax has been (mostly) Finalized

Post icon  Posted 09 September 2011 - 09:24 AM

*
POPULAR

http://mail.openjdk....ber/003936.html

Quote

After considering a number of alternatives, we decided to essentially
adopt the C# syntax.


Quote

The C# syntax is:

lambda = ArgList Arrow Body
ArgList = Identifier
| "(" Identifier [ "," Identifier ]* ")"
| "(" Type Identifier [ "," Type Identifier ]* ")"
Body = Expression
| "{" [ Statement ";" ]+ "}"

Here are some examples of lambda expressions using this syntax:

x => x + 1
(x) => x + 1
(int x) => x + 1
(int x, int y) => x + y
(x, y) => x + y
(x, y) => { System.out.printf("%d + %d = %d%n", x, y, x+y); }
() => { System.out.println("I am a Runnable"); }


Is This A Good Question/Topic? 5
  • +

Replies To: Java 8 Lambda Syntax has been (mostly) Finalized

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,462
  • Joined: 29-May 08

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 09:30 AM

Microsoft should a Java and sue them for infringing their design.
Was This Post Helpful? 0
  • +
  • -

#3 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 09:51 AM

Oh god I wish I could see the look on the faces of every Java dev who told me C# was inferior because it belonged to "Micro$shaft" as they put it.

Good addition to Java, C# has it and it's a god send.
Was This Post Helpful? 1
  • +
  • -

#4 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 838
  • Posts: 2,573
  • Joined: 29-July 11

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 10:23 AM

Lambdas are a big confusing mess. I look at that syntax and want to avoid it at all costs.

c# is superior to Java in many ways. I especially like the fact that I can implements two interfaces with the same method names. That being said, beyond doing development for Xbox or windows phone, I see no reason to use c#, ever.

This post has been edited by farrell2k: 09 September 2011 - 10:25 AM

Was This Post Helpful? -1
  • +
  • -

#5 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,065
  • Joined: 27-December 08

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 10:41 AM

Very interesting that Oracle decided to adopt the C# syntax for this. Java 8 probably won't be out for another couple years at least (especially since Java 7's official release was fairly recent), so it's not likely we'll be using this syntax in the near future. :(

Quote

I especially like the fact that I can implements two interfaces with the same method names.

You can do this in Java as well.
Was This Post Helpful? 0
  • +
  • -

#6 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 838
  • Posts: 2,573
  • Joined: 29-July 11

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 12:22 PM

View Postmacosxnerd101, on 09 September 2011 - 05:41 PM, said:

Very interesting that Oracle decided to adopt the C# syntax for this. Java 8 probably won't be out for another couple years at least (especially since Java 7's official release was fairly recent), so it's not likely we'll be using this syntax in the near future. :(

Quote

I especially like the fact that I can implements two interfaces with the same method names.

You can do this in Java as well.


I am pretty sure you're wrong about that. Two separate interfaces with the same method names is too ambiguous. In c# you can explicitly refer to the method names, (Interface1.method()) whereas in Java you cannot. Unless I am completely wrong, which I usually am more often than not. :)
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,065
  • Joined: 27-December 08

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 12:33 PM

Proof of concept:
interface A{ void foo(); }
interface B{ void foo(); }

class C implements A, B{ 
   public void foo(){} 

}

....
A a = new C();
a.foo();

B b = new C();
b.foo();


Was This Post Helpful? 1
  • +
  • -

#8 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4479
  • View blog
  • Posts: 7,801
  • Joined: 08-June 10

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 01:07 PM

What he means is that in C# you can do this:

public class Program {
    public static void Main(string[] args) {
        var c = new C();
        (c as IA).Foo();
        (c as IB).Foo();
        Console.ReadKey();
    }
}

public interface IA {
    void Foo();
}

public interface IB {
    void Foo();
}

public class C : IA, IB {
    void IA.Foo() {
        Console.WriteLine("IA Foo");
    }

    void IB.Foo() {
        Console.WriteLine("IB Foo");
    }
}



You can explicitly implement two different methods with the same name from different interfaces.
Was This Post Helpful? 2
  • +
  • -

#9 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,065
  • Joined: 27-December 08

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 01:07 PM

Ah, so that's what he meant. My bad. :)
Was This Post Helpful? 0
  • +
  • -

#10 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 01:14 PM

language barrier? :P
Was This Post Helpful? 0
  • +
  • -

#11 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 838
  • Posts: 2,573
  • Joined: 29-July 11

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 01:33 PM

View Postmacosxnerd101, on 09 September 2011 - 07:33 PM, said:

Proof of concept:
interface A{ void foo(); }
interface B{ void foo(); }

class C implements A, B{ 
   public void foo(){} 

}

....
A a = new C();
a.foo();

B b = new C();
b.foo();



In this instance, is there a way for foo() to behave differently, depending on whether a.foo() or b.foo() is called?

As to not hijack this thread, this should probably be moved to Programming Help -> Java. Apologies.

This post has been edited by farrell2k: 09 September 2011 - 01:34 PM

Was This Post Helpful? 0
  • +
  • -

#12 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,065
  • Joined: 27-December 08

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 02:26 PM

Not really. I misunderstood your original question. Sorry for the confusion. :)
Was This Post Helpful? 0
  • +
  • -

#13 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1985
  • View blog
  • Posts: 4,119
  • Joined: 11-December 07

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 05:13 PM

Good to see progress here! I hope that when Java 8 comes out with lambdas they retrofit Collections with internal iterators.
Was This Post Helpful? 0
  • +
  • -

#14 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 611
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 06:32 PM

View Postfarrell2k, on 09 September 2011 - 06:23 PM, said:

Lambdas are a big confusing mess. I look at that syntax and want to avoid it at all costs.

c# is superior to Java in many ways. I especially like the fact that I can implements two interfaces with the same method names. That being said, beyond doing development for Xbox or windows phone, I see no reason to use c#, ever.


Lambdas are a very high level and powerful programming tool that absolutely *no* modern programming language should be without. I highly suggest that you investigate lambdas and functional programming a bit more before making such harsh judgements. I'm certain you'll find that you can do things with them that you wouldn't have otherwise thought possible.
Was This Post Helpful? 0
  • +
  • -

#15 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Java 8 Lambda Syntax has been (mostly) Finalized

Posted 09 September 2011 - 09:25 PM

Where would I be without lambdas? Coding like it's 1996, oh yeah baby! :pimp:

Lambdas are fantastic.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2