在查看代码的某个时候,我看到许多方法都指定了注释:
@SuppressWarnings("unchecked")
Run Code Online (Sandbox Code Playgroud)
这是什么意思?
我有一个ArrayList,我在ArrayAdapter中使用ListView.我需要获取列表中的项目并将它们转换为JSONArray以发送到API.我已经四处寻找,但没有找到任何解释这可行的方法,任何帮助都会受到赞赏.
更新 - 解决方案
以下是我最终要解决的问题.
ArrayList中的对象:
public class ListItem {
private long _masterId;
private String _name;
private long _category;
public ListItem(long masterId, String name, long category) {
_masterId = masterId;
_name = name;
_category = category;
}
public JSONObject getJSONObject() {
JSONObject obj = new JSONObject();
try {
obj.put("Id", _masterId);
obj.put("Name", _name);
obj.put("Category", _category);
} catch (JSONException e) {
trace("DefaultListItem.toString JSONException: "+e.getMessage());
}
return obj;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我如何转换它:
ArrayList<ListItem> myCustomList = .... // list filled with objects
JSONArray jsonArray = …Run Code Online (Sandbox Code Playgroud) 自从我做了一些java编码以来已经有一段时间了.
我需要为需要自动化的业务(研讨会的一部分)构建一个应用程序,但这与我的问题无关......
我被困在线上:customerList.add(客户); //(WCIA类中的addCustomer方法的一部分)另外,这是我第一次被告知"将返回值赋给新变量"作为错误的一部分,因此不太清楚这意味着什么.
代码:主要
import java.util.ArrayList;
public class WCIA {
private final ArrayList customerList = null;
public static void main(String[] args) {
short s =002;
Customer arno = new Customer();
arno.setName("Arno");
arno.setId(s);
arno.setEmail("arnomeye@gmail.com");
arno.setAddress("Somewhere");
arno.setPhoneNum("0727855201");
System.out.printf("%s",arno.getEmail());
WCIA wcia = new WCIA();
wcia.addCustomer(arno);
wcia.displayCustomers();
}
public void addCustomer (Customer customer)
{
customerList.add(customer); // <---Problem over here
}
public void displayCustomers()
{
for(int x=0;x<customerList.size();x++)
{
Customer cus = (Customer) customerList.get(x);
cus.DisplayCustomer();
}
}
}
Run Code Online (Sandbox Code Playgroud)
代码:客户类:
public class Customer {
private short …Run Code Online (Sandbox Code Playgroud) 我正在使用Liferay 6.1开发一个portlet Liferay MVC famework.我用的时候
<liferay-ui:search-container />
Run Code Online (Sandbox Code Playgroud)
Eclipse总是向我显示以下警告消息
SearchContainer是一种原始类型.
SearhcContainer<R>应参数化对泛型类型的引用
JSP代码片段:
<%
List<User> users = UserLocalServiceUtil.search(...);
%>
<liferay-ui:search-container>
<liferay-ui:search-container-results
results="<%= users %>"
total="<%= users.size() %>"
/>
<liferay-ui:search-container-row
className="com.liferay.portal.model.User"
keyProperty="userId"
modelVar="userVar">
<liferay-ui:search-container-column-text
name="name"
value="<%= userVar.getFullName() %>" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
Run Code Online (Sandbox Code Playgroud)
我搜索了很多例子.我已将它们导入我的工作区.当使用search-container标记时,它们也会向我显示相同的警告消息.
一个例子是此portlet:事件列出的portlet
中/docroot/html/eventlisting/view.jsp Eclipse中显示我同样的警告.
我没有在stackoverflow中找到任何搜索解决方案,也没有找到google.我在jsp中发现了很多对警告的引用,但是当使用某些标记时发生警告时没有.
如果可能,我不想禁用JSP验证或使用一些@SuppressWarnings.
我真的想知道在使用这个taglib时是否有正确的方法来避免JSP中的这个警告.
我正在使用
- Liferay 6.1.1 CE GA2
- Eclipse Luna Release 4.4.0
提前致谢