我收到错误:
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;
}