lambda in a static method of an interface (original) (raw)
Remi Forax forax at univ-mlv.fr
Mon Apr 1 05:04:24 PDT 2013
- Previous message: flatMap signature
- Next message: lambda in a static method of an interface
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
This code currently compiles but doesn't work at runtime
public interface User { public default String firstName() { return transform(0); }
public default String lastName() { return transform(1); }
public abstract String transform(int index);
public static User User(String firstName, String lastName) { return ref -> (ref == 0)? firstName: lastName; }
public static void main(String[] args) { User bob = User("Bob", "Vance"); System.out.println(bob.firstName()); System.out.println(bob.lastName()); } }
Exception in thread "main" java.lang.IncompatibleClassChangeError: Class java.lang.String does not implement the requested interface User at User$$Lambda$1.transform(Unknown Source) at User.firstName(User.java:3) at User$$Lambda$1.firstName(Unknown Source) at User.main(User.java:18)
I believe it's a bug in javac, the desugared method is not declared static but should: public java.lang.String lambda$0(java.lang.String, java.lang.String, int);
BTW, I use the b83 binary build, not the lastest mecurial tip.
cheers, Rémi
- Previous message: flatMap signature
- Next message: lambda in a static method of an interface
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]