import java.util.ArrayList;
import java.util.List;
public class UserTools {
public static List<String> getAdminNameList(List<User> list) {
List<String> result = new ArrayList<String>();
for (User user : list) {
if (user.isAdmin()) {
result.add(user.getName());
}
}
return result;
}
}
importjava.util.ArrayList;
importjava.util.List;
publicclassUserTools {
publicstaticList<String> getAdminNameList(List<User> list) {
List<String> result = newArrayList<String>();
for (User user : list) {
if (user.isAdmin()) {
result.add(user.getName());
}
}
return result;
}
}
Corresponding Xtend code:
xtend
import java.util.List
class UserTools {
def static getAdminNameList(List<User> list) {
list.filter [ admin ].map [ name ]
}
}