0

エラーが発生します:

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;
    }
4

3 に答える 3

1

これは非常に奇妙なコードです:

(List<Person>) (List<?>) group.getRecipients()

何をgetRecipients()返しますか?そして、なぜあなたは2回キャストしていますか?group.getRecipients() は List 以外のものを返すようですか?

于 2013-10-15T12:18:39.777 に答える
1

コードからわかること

 (List<Person>) (List<?>) group.getRecipients()

Group を Person クラスにキャストしようとしていて、エラーが何を示しているか..

于 2013-10-15T12:18:51.607 に答える