エラーが発生します:
java.lang.ClassCastException: Group cannot be cast to Person
のため
Type safety: Unchecked cast from List<capture#1-of ?> to List<Person>
コードから:
List<Person> arrangedPerson = PersonAddImportHelper.setChannelInfo(
(List<Person>) (List<?>) group.getRecipients(), model);
at ui.PersonAddImportHelper.setChannelInfo(PersonAddImportHelper.java:42)
at ui.GroupMembersController.viewGroupMembers(GroupMembersController.java:170)
からGroupMembersController.viewGroupMembers (GroupMembersController.java:170)
@RequestMapping(value = "/list/{id}/{page}", method = RequestMethod.GET)
public String viewGroupMembers(@PathVariable("id") final Group group,
@PathVariable("page") final int page,
@RequestParam(value = "pageSize", defaultValue = DEFAULT_PAGE_SIZE) final int pageSize,
@RequestParam(value = "search", defaultValue = "") final String search,
@RequestParam(value = "sortColumn", defaultValue = "lastname") final String sortColumn,
@RequestParam(value = "filter", defaultValue = "") final String filter,
final Model model) {
List<Person> arrangedPerson = PersonAddImportHelper.setChannelInfo(
(List<Person>) (List<?>) group.getRecipients(), model);
for (Person person : arrangedPerson) {
group.addMember(person);
}
list(group, page, Integer.valueOf(pageSize), search, sortColumn, filter, model);
model.addAttribute("group", group);
return "/recipient/groupPersonList";
}
そしてui.PersonAddImportHelper.setChannelInfo
、次のとおりです。
public static List<Person> setChannelInfo(final List<Person> items,
final Model model) {
List<Person> arrangedPerson = new ArrayList<>();
final Map<Person, Boolean> hasEmail = Maps
.newHashMapWithExpectedSize(items.size());
final Map<Person, Boolean> hasFixed = Maps
.newHashMapWithExpectedSize(items.size());
final Map<Person, Boolean> hasMobile = Maps
.newHashMapWithExpectedSize(items.size());
for (Person person : items) {
List<Address> addresses = ((Person) person).getAddresses();
List<Address> arrangedAddresses = new ArrayList<Address>(
Arrays.asList(new Address[ADDRESS_MAX_SIZE]));
int mobileIndex = 0;
int fixedIndex = 2;
int emailIndex = ADDRESS_PHONE_START_INDX;
for (Address address : addresses) {
// some Logic
}
((Person) person).setAddresses(arrangedAddresses);
arrangedPerson.add(person);
}
model.addAttribute("hasEmail", hasEmail);
model.addAttribute("hasFixed", hasFixed);
model.addAttribute("hasMobile", hasMobile);
return arrangedPerson;
}