在 android kotlin 中获取文件名

get name of file in android kotlin

我在文件中有一个名为 StringEx.kt 的扩展函数。

StringEx.kt

package com.example
        
fun String.addUnderline(): String {
    return "_" + this + "_"
}

如何获取其他class中文件("StringEx.kt")的名称和包?

例如:

println(StringEx:class.name)
// print com.example.StringEx

这里您没有创建 class。相反,您只是在创建扩展功能而没有 class 你怎么能得到它的包名。 class“字符串”不属于“com.example”包