Dion says (http://www.almaer.com/blog/archives/000639.html):
I think that the Arrays.* methods are not that well known among Java developers.
But it's not true. If your application involved with any remoting ... in fact, any customized serialization (such as XMLEncoder/XMLDecoder), Arrays.asList() can be an error prone. Its result is of type java.util.Arrays$ArrayList, a private type, so serialization framework cannot instantiate it. And so...
For example, you can run the following JUnit test case:
public void testXmlSerialize() throws Exception {
Object[] anArray = new Object[]{"Jeff"};
List aList = Arrays.asList(anArray);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(baos);
encoder.writeObject(aList);
encoder.close();
byte[] someBytes = baos.toByteArray();
String result = new String(someBytes);
System.out.println(result);
// huh, our content is missed
assertTrue(result.indexOf("Jeff") == -1);
}
I found this bug when using Hessian remoting. If you want some simplified syntax for List initialization, try this:
List aList = new ArrayList() {
{
add("Jeff");
add("Gigix");
}
};
- 作者: 透明 2005年01月18日, 星期二 17:41
你可以使用这个链接引用该篇日志 http://publishblog.blogdriver.com/blog/tb.b?diaryID=503885
nvxwxwmecw[url=http://zvore.yi.org/82177478.html]brazilian pussy[/url][url=http://xenggi.66ghz.com/46330167.html]gun games[/url][url=http://wxaxw.22web.net/34298878.html]tatoo designs[/url][url=http://www32.websamba.com/viora/94041272.html]model com[/url][url=http://uenvc.22web.net/16709694.html]football games[/url][url=http://ninfrb.yi.org/20352297.html]blades glory cam xvid mvs[/url]
ktxwxwmezt[url=http://zvore.yi.org/82177478.html]brazilian pussy[/url][url=http://xenggi.66ghz.com/46330167.html]gun games[/url][url=http://wxaxw.22web.net/34298878.html]tatoo designs[/url][url=http://www32.websamba.com/viora/94041272.html]model com[/url][url=http://uenvc.22web.net/16709694.html]football games[/url][url=http://ninfrb.yi.org/20352297.html]blades glory cam xvid mvs[/url]
xpxwxwmetw[url=http://zvore.yi.org/82177478.html]brazilian pussy[/url][url=http://xenggi.66ghz.com/46330167.html]gun games[/url][url=http://wxaxw.22web.net/34298878.html]tatoo designs[/url][url=http://www32.websamba.com/viora/94041272.html]model com[/url][url=http://uenvc.22web.net/16709694.html]football games[/url][url=http://ninfrb.yi.org/20352297.html]blades glory cam xvid mvs[/url]