RandomAccessSubList未序列化

Omn*_*ent 1 java list

我想获得一个子列表,List但我希望子列表被序列化.我发现当我们从子列表中获取子ArrayList列表时没有序列化.

要克服这一点,我正在做的事情:

ArrayList serializedSublist = new ArrayList();
//getQuestions() returns RandomAccessSubList
getQuestions().addAll(serializedSublist); 
//problem is in the line below. serializedSublist is empty.
getRequest().getSession().setAttribute("questionsForUser", serializedSublist);
Run Code Online (Sandbox Code Playgroud)

问题是serializedSubList第5行是空的,尽管第3行getQuestions()返回了一个列表.

Chs*_*y76 8

你向后添加它,不是吗?不应该

serializedSublist.addAll(getQuestions());
Run Code Online (Sandbox Code Playgroud)

或者,更好的是

ArrayList serializedSublist = new ArrayList(getQuestions());
Run Code Online (Sandbox Code Playgroud)