hg: lambda/lambda/langtools: Implemented features are:
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri Jul 30 10:51:45 PDT 2010
On 30/07/10 17:36, Paul Benedict wrote:
> Maurizio,
>
> This looks really good. Forgive me if wrong, but I noticed the SAM
> conversion functionality is (like) duck typing. The lambda expression
> can get wrapped in an Interface proxy of the appropriate signature.
>
> I made an example of my own. Should I expect this to compile? If so,
> what should I expect from my instanceof assertions?
Hi Paul,
your example compiles, however the second instanceof fails at runtime
(as the method reference is not an instanceof Foo)...
Note that the instance of passes compilation because of the 'side-cast'
rules (that is, there might be a subclass of Foo that implements Getter
- as such, statically rejecting the instanceof would have been to harsh).
Maurizio
>
> public class MethodReferenceXX {
> interface Getter<T> {
> public T get();
> }
>
> static class Foo {
> public Integer get() {
> return 0;
> }
> }
>
> public static <T> T test(Getter<T> getter) {
> assertTrue(getter instanceof Getter);
> assertTrue(getter instanceof Foo);
> return getter.get();
> };
>
> public static void main(String... args) {
> Foo foo = new Foo();
> test(foo#get);
> }
> }
>
> Paul
>
> On Fri, Jul 30, 2010 at 9:49 AM, <maurizio.cimadamore at oracle.com
> <mailto:maurizio.cimadamore at oracle.com>> wrote:
>
> Changeset: b4b3b410e1c1
> Author: mcimadamore
> Date: 2010-07-30 15:47 +0100
> URL:
> http://hg.openjdk.java.net/lambda/lambda/langtools/rev/b4b3b410e1c1
>
> Implemented features are:
>
> *) Method References
> Method references have been implemented using the 'infix' notation
> suggested by John Rose. For example, a method reference for a
> method m in class A is denoted as 'A#m'. Method references can
> include an actual argument types list (in order to disambiguate in
> case of overload resolution). Big thanks to John Rose, as I
> re-used most of the code for handling code generation of method
> handle literals.
>
> *) Effectively final analysis
> Local variables that are never assigned can now be referenced from
> a lambda body.
>
> *) Removed explicit support for function types
> The option -XDallowFunctionTypes has been removed. As a result,
> SAM types are the only legitimate target types for lambda
> expressions/method refs.
>
> *) Miscellaneous bug fixes (thanks to Peter Levart for the feedback).
>
> TODO:
>
> *) break/continue/return
>
>
More information about the lambda-dev
mailing list