I am making a custom view for Android. I am going to clone the layout by calling clone (this), but it shows error, when I use clone (this@mycustomclassname), it works.

It's still confused. Anyone knows the meaning of this@classname in kotlin?

推荐答案

This is a qualified this. You can access this from an outer scope.

As this can mean different things (part the referenced page):

To denote the current receiver, we use this expressions:

  • In a member of a class, this refers to the current object of that class.
  • In an extension function or a function literal with receiver this denotes the receiver parameter that is passed on the left-hand side of a dot.

Kotlin相关问答推荐

了解Kotlin函数

如何为集成测试配置Gradle JVM测试套件?

在Kotlin中求n个ClosedRange实例相交的最常用方法是什么?

为什么使用 return instance ?: synchronized(this) { instance ?: PreferenceParameterState(context) } 时无法获得单例?

Kotlin 基于参数类型的返回类型推断

Kotlin supervisorScope 即使包裹在 try catch 中也会失败

如何将 `throw` 放置在辅助函数中但仍然具有空安全性?

正则表达式 FindAll 不打印结果 Kotlin

kotlin 单例异常是好是坏?

错误:cannot find symbol import com.gourav.news.databinding.ActivityDetailBindingImpl;

Kotlin JS JSON 反序列化

IntentService (kotlin) 的默认构造函数

androidx.core:core-ktx:1.0.0 小部件包丢失

在用Kotlin编写的Android库公共API中处理R8+JvmStatic Annotation+Lambda

哪里可以找到aapt2日志(log)?

取消信号上的kotlin流量采集

无法解决:androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1

如果kotlin已经有了getter和setter,为什么在数据类中有componentN函数?

在Kotlin中将列表转换为对的惯用方法

有没有办法在Kotlin中设置一个私有常量