类型List的表达式需要未经检查的转换以符合List< CategoryTypes>

时间:2017-01-08 02:41:52

标签: liferay-6

我有这段代码:

      <tr>
        <td><p><%= image_tag("zombie_profile.png", width: '100px') %><%= gurgle.status %></p></td>
        <td><p><%= @user.email %></p></td>
      </tr>
    </tbody>
</table>
  

&#34; List类型的表达式需要未经检查的转换才能符合   列表与LT; CategoryTypes&gt;&#34;

如何修复我的代码以删除此警告?

1 个答案:

答案 0 :(得分:0)

首先将此方法添加到您的课程中:

public static <T> List<T> castList(Class<? extends T> clazz, Collection<?> c) {
    List<T> r = new ArrayList<T>(c.size());
    for(Object o: c)
      r.add(clazz.cast(o));
    return r;
}

试试这个:

DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(OpenBoard.class);
DynamicQuery categoryQuery = DynamicQueryFactoryUtil.forClass(CategoryTypes.class);
User user=UserLocalServiceUtil.getUser(PortalUtil.getUserId(request));
categoryQuery.add(RestrictionsFactoryUtil.eq("categoryTarget",String.valueOf("O")));
List<CategoryTypes> category_list = castList(CategoryTypes.class, CategoryTypesLocalServiceUtil.dynamicQuery(categoryQuery));

参考书目:https://stackoverflow.com/a/2848268/6676203