Dennis Sosnoski
2014-04-03 04:52:38 UTC
I've run into an interesting issue in the code for an upcoming article.
This works:
public class Name {
public final String firstName;
public final String lastName;
public Name(String first, String last) {
firstName = first;
lastName = last;
}
...
}
Comparator<Name> comp = Comparator.comparing(name ->
name.lastName);
comp = comp.thenComparing(name -> name.firstName);
But this gives compile errors (and errors on the "name" symbol), even if
I use a cast on the second lambda:
Comparator<Name> comp = Comparator.comparing(name1 ->
name1.lastName)
.thenComparing(name2 -> name2.firstName);
I'm wondering if it's a compiler bug, or just somehow a consequence of
the lambda target typing rules:
http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#target-typing
Any thoughts?
- Dennis
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/seajug/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/seajug/join
(Yahoo! ID required)
<*> To change settings via email:
seajug-digest-***@public.gmane.org
seajug-fullfeatured-***@public.gmane.org
<*> To unsubscribe from this group, send an email to:
seajug-unsubscribe-***@public.gmane.org
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/
This works:
public class Name {
public final String firstName;
public final String lastName;
public Name(String first, String last) {
firstName = first;
lastName = last;
}
...
}
Comparator<Name> comp = Comparator.comparing(name ->
name.lastName);
comp = comp.thenComparing(name -> name.firstName);
But this gives compile errors (and errors on the "name" symbol), even if
I use a cast on the second lambda:
Comparator<Name> comp = Comparator.comparing(name1 ->
name1.lastName)
.thenComparing(name2 -> name2.firstName);
I'm wondering if it's a compiler bug, or just somehow a consequence of
the lambda target typing rules:
http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#target-typing
Any thoughts?
- Dennis
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/seajug/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/seajug/join
(Yahoo! ID required)
<*> To change settings via email:
seajug-digest-***@public.gmane.org
seajug-fullfeatured-***@public.gmane.org
<*> To unsubscribe from this group, send an email to:
seajug-unsubscribe-***@public.gmane.org
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/