Hacker News new | past | comments | ask | show | jobs | submit | javafu2's comments login

It already exists in the API. Your type Projection is a Function, and by is called comparing in interface Comparator.

so one can write: ``` contries.sorted(comparingInt(Country::getPopulation)). ... ```


In my opinion, lambdas were not introduced in Java before now because Java as already anonymous classes that are at a high level conceptually the same things even if a lambda is more lightweight syntactically and at runtime than an anonymous class


checked exceptions :), sorry just kidding.

mainly wildcards, you can design an interface which is covariant and contravariant, and real interference when calling a generic method.


You can not modified a variable declared in the outer scope inside a lambda.

int a = 0; list.forEach(element -> { a++; // no way ! });

That's why it's a lambda and not a closure BTW.


Can always make:

   final int[] a = {0};
   list.forEach(element -> { a[0]++; });


It's still a closure, just a closure with immutable capture, just like Python. Also like Python, you can get around it by boxing the variable you would like to modify (or using nonlocal in Python 3).

IMO the lack of exception transparency is going to be more of an issue with Java's lambdas.


For most of the used programming languages, a lambda captures values (like in Java or Python), and closure capture variables or scope (like in Scheme or Ruby), hence the name, a closure close (bind) the free variable of the closure to the ones of the lexical scope.

The lack of checked exception transparency is for me something that goes in the right direction. The hidden message is 'Use checked exception only for IOs and please don't create your own exceptions, use already existing ones !'


A lambda doesn't capture anything, it's just an anonymous function. A lambda can be a closure, but it doesn't have to be.

Closures come in two primary flavors, bind by value or bind by reference. Some languages implement only one of these, some implement both, some bind in completely different ways (e.g. lazy binding in Haskell).


F# team ask for modifications of the CLR (covariant delegates), porting a language on the CLR if you are not Microsoft is hard.

Scala never really run on the CLR, it's a vaporware, sorry a work in progress.


Yep, scala's .net back-end is discontinued, and one of the main challenges (I worked on it a bit) was indeed generating the proper generic signatures. (I hear people are using ikvm these days.)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: