"extract" using subsequent invocation call - ClassCastException problem

15 views
Skip to first unread message

IT Tudes

unread,
May 4, 2012, 6:23:13 AM5/4/12
to lambdaj
Hi all,
I'm trying to extract and then join an attribute from collection.
Going more in detail, I would extract email attribute from collection
of User with a subsequent invocation call:
user.getUserDetails().getEmail()

Here the User.class snippet:
public interface User {
...
UserDetails getDetails();
...
}

Here UserDetails snippet:
public class UserDetails {
private String email;
public String getEmail() {
return email;
}
...
}

And finally here the lambdaj code I'm using:

List<User> allUsers = ...
String allRecipients = joinFrom(extract(allUsers,
on(User.class).getDetails().getEmail()));

The above code is throwing the exception:
java.lang.ClassCastException: $java.lang.Iterable$$EnhancerByCGLIB$
$bcf8cb71 cannot be cast to java.lang.String

Could you please help me?

Regards,
Alex

Mario Fusco

unread,
May 5, 2012, 4:15:07 AM5/5/12
to lam...@googlegroups.com
Hi Alex,

you're mixing 2 lambdaj feature in the wrong way. To achieve what you wanted to do you can either write:

String allRecipients = join(extract(allUsers, on(User.class).getDetails().getEmail()));

or more easily:

String allRecipients = joinFrom(allUsers).getDetails().getEmail();

Let me know if this works.

Regards,
Mario
Reply all
Reply to author
Forward
0 new messages