Object (@Nullable Object context, @NotNull List<? extends Element> elements) { Collection<Object> result; boolean isContextMutable = context != null && ClassUtil.isMutableCollection(context); if (isContextMutable) { //noinspection unchecked result = (Collection<Object>)context; result.clear(); } else { result = context instanceof Set ? new HashSet<>() : new ArrayList<>(); } for (Element node : elements) { result.add(deserializeItem(node, context)); } return result; }