RandomAccessSubList未序列化 [英] RandomAccessSubList not serialized
本文介绍了RandomAccessSubList未序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取List
的子列表,但是我希望该子列表被序列化.我发现,当我们从ArrayList
获取子列表时,该子列表未序列化.
I am trying to get a sublist of a List
but I want the sublist to be serialized. I found out that when we get sublist from an ArrayList
the sublist is not serialized.
要克服这一点,这就是我正在做的事情:
To overcome this, this is what I am doing:
ArrayList serializedSublist = new ArrayList();
//getQuestions() returns RandomAccessSubList
getQuestions().addAll(serializedSublist);
//problem is in the line below. serializedSublist is empty.
getRequest().getSession().setAttribute("questionsForUser", serializedSublist);
问题是,尽管第3行getQuestions()
返回了列表,但第5行中的serializedSubList
为空.
Problem is that serializedSubList
is empty in line 5, eventhough in line 3 getQuestions()
returns a list back.
推荐答案
您正在向后添加它,不是吗?不应该吧
You're adding it backwards, no? Shouldn't it be
serializedSublist.addAll(getQuestions());
或者更好
ArrayList serializedSublist = new ArrayList(getQuestions());
这篇关于RandomAccessSubList未序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文