DeepCopy.kt 文件 , 内容如下: packagecom.stone.demo.basic.deepcopy1classDeepCopy{}interfaceDeepCopyable<outR>{fundeepCopy():R}// 一. kotlin实现对象的深度拷贝// 实现方式: 使用 直接 "创建对象" 的方式实现深度拷贝// 优点: 可以用于 "data-class" 和 "非data-class"// 缺点: a. 需要实现接口...
这里我们发现有两个deepReCopy,这是因为我想让它支持DSL写法,传入copyFunction的就是支持DSL写法的函数,刚刚我们调用的就是它啦。 目前DeepReCopy已经支持了List、Map、Set的深拷贝,对于其他没有被@EnhancedData注解的对象,我们会检查是否实现了序列化接口,假设没有则检查是否存在clone方法,假设都不具备那么对这个对象就...
/深拷贝fun<T:Any>T.deepCopy():T{valcopiedObjects=mutableMapOf<Any,Any>()varinitialObject=getValueFromCopiedCollection(this,copiedObjects)initialObject=deepCopy(this,copiedObjects)returninitialObject}privatefun<T:Any>deepCopy(obj:T,copiedObjects:MutableMap<Any,Any>):T{valobjClassJava=obj::class....
data class Container(val list: MutableList<String>) fun main(args: Array<String>) { val list = mutableListOf("one", "two") val c1 = Container(list) val c2 = c1.copy() list += "oops" println(c2.list.joinToString()) } 1. 2. 3. 4. 5. 6. 7. 8. 9. 以上代码,运行结果是什么?
classDeepCopyList<T>(privatevalinstance:DeepCopy<T>):DeepCopy<MutableList<T>>{overridefundeepCopy(x:MutableList<T>)=x.map{instance.deepCopy(it)}.toMutableList()} 注:这里的实现需要一个.toMutableList(),其实深究起来,也是因为kotlin没有typeclass能力,以及没有高阶类型(hkt),导致任何迭代器类型调用ma...
copyFromRealm(depth: UInt = UInt.MAX_VALUE): List<T> Makes an unmanaged in-memory copy of the elements in a RealmResults. This is a deep copy that will copy all referenced objects. inline fun <T : RealmObject> RealmDictionary<T?>.copyFromRealm(depth: UInt = UInt.MAX_VALUE): Map<...
nav = copy.deepcopy(nav) if build_mode: _nav_cache = copy.deepcopy(nav) # NOTE. This call depends on `request.path`, cannot cache process_nav(request.path, nav) return nav def get_nav_impl(): with open(path.join(data_folder, "_nav.yml")) as stream: nav = yaml.load(stream)...
(): List<UserDTO>}abstract class SuperType<t> {val typeParameter by lazy {/*** 抽象类不能有实例,所以这里的 this 是子类的* supertypes:获取父类类型列表* first:获取第一个* arguments:拿到泛型* type:类型*/this::class.supertypes.first().arguments.first().type!!}val typeParameterJava by ...
val helper = PageListCacheHelper(context.filesDir.absolutePath) helper.remove(key) 4)jsoup获取数据 由于数据是用从html页面中提取的,所以速度偏慢,为了不影响体验做了一套缓存机制,来做到流畅体验。 Document doc = Jsoup.parse(html); Elements elements = body.getElementsByTag("a"); ...
user=User(id=0, username="vince", age=28) database.users.add(user, useGeneratedKey=true)//Database.users is an extension property generated by Ktorm KSP.//Use the entity sequence API to fetch all users under 28 from the table.valusers=database.users.filter { it.age lte28}.toList()...