Yes, the legal narrative is certainly key here, but as a dev I'm all for a move that brings Java 8 to Android instead of just Java 6. It's about time!
Yes, the legal narrative is certainly key here, but as a dev I'm all for a move that brings Java 8 to Android instead of just Java 6. It's about time!
1. Use RetroLambda
2. Write your own implementation of Streams and Optionals, compatible with RxJava and Guava
3. Use in your project
4. ProfitOften (ButterKnife, NineOldAndroids, etc) even better than what Google themselves provide.
In (pre-8) Java, variables can only hold primitive values or objects (in Java, an object is an instance of a class [c.f.]). Similarly, arguments to a method must all be primitive values or objects.
This is kinda crazy, by which I mean hilariously limiting. It's often useful to pass around other types of things, including types (in Java that'd be primitive types or classes or interfaces), or functions, or partially applied functions, or whatever. Of course, Java doesn't have functions, only methods. Whoops. See http://steve-yegge.blogspot.ca/2006/03/execution-in-kingdom-... for a bit of snark about how silly this whole situation is.
So Java programmers, while desperately lacking in aesthetic taste (I keed, I keed) and largely blinkered by the java-cultural context in which they find themselves, turn out to be a pretty clever lot after all. Clever enough that despite their language, they come up with all these conventions for doing things like passing around types and functions and so on. So you get ideas like the Runnable interface, wherein one makes a class just so that it can have a static method (perhaps called "run") that does what the function would do, and you then instantiate that class, and pass the instance, just so it can be used to get at the "run" method. It works, but it's oh so ugly.
So finally, after twenty years of this suffering, now Java programmers have some nice new syntactic sugar, to allow them to pass functions around with less explicit ceremony, thereby catching up with advanced languages like Python, C, Lisp, and basically everything except Cobol. Of course, under the hood it's still Predicate<T>, a generic type that represents a functional interface, which is a new bit of jargon they came up with to shoehorn this elementary functionality into their baroque conceptual framework. And you furthermore, in Java 8 you can even declare them anonymously (unlike e.g. C, AFAIK), to expedite the most common use case, which is passing a function as an argument to a higher-order function (like "map" or whatever). They're called "lambdas" because of the existence of the lambda calculus, an abstraction for computing that uses nothing but anonymous functions, and because many other languages have therefore referred to their anonymous function syntax as "lambdas" (Python even uses "lambda" as a keyword for this).
So the big deal about lambdas in Java is that Java has one less vile pain point.
(Any five-year-old could understand this explanation, right?)
I understand the use case of passing functions. Can be quite useful. Ok, still not fully there but I think I'm starting to understand what you are talking about.
Consider, for example, how you'd pass a specialized comparator to a generalized quicksort function. In C, you pass a function pointer to a cmp() function. In Python you just pass a function, because functions are first-class values that you can use like anything else - you can pass it by name, or you can pass a lambda. In Javascript you can do like in Python, or you can declare a full-fledged function anonymously inline. In pre-8 Java, you have to pass a weird object that instantiates a class that has a static method with the right name; this is ugly as shit, but it does WORK. In Java 8 you've got lambdas, so that sucks less.
It's not like you can do anything you couldn't do before. It's just a little less stupid now.