How to create a deep copy of a class that is passed as an interface?

I have a function that takes a Collection, and one of the things I want to do in it is create a deep copy so when I alter the values, it does not alter the data in the passed Collection. I’m not sure how to create a deep copy of something when you don’t know what class it is at compile-time, or if it’s even possible.

fun foo(coll: Collection<T>) { // I don't know what kind of collection coll is, it could be a List, a Set, etc. // but I want to create a deep copy of it to avoid side-effects newColl = // create a deep copy of coll here } 

Does anyone know how I could do this? Thanks!

submitted by /u/LobsterCoordinates
[link] [comments]