I take like this:
Collection<TaskComment> commentsCollection = task.getComments();
ArrayList<TaskComment> comments = new ArrayList<>(commentsCollection);
for(TaskComment cmnt : comments){
cmnt.setUser(commentUser.getLogin());
cmnt.setCreatedAtString(cmnt.getCreatedAt().format(DateTimeFormatter.ofPattern(Constants.DATE_TIME_FORMAT)));
}
Here I take comments and put them into a collection, then into an arraylist. Then I manipulate the comments with DTO class methods.
But when I change cmnt
, the comments from task.getcomments
changes.
I think this code is enough but I can give more code if you want. Why does it change? It was supposed not to change because I moved it to collection then to array?
I don't do this:
repository.save(task);
after I manipulate the comment, so it must not save to database? So why does
task.getComments();
return changed data? I did not save to database?