简体   繁体   English

在android kotlin中获取文件名

[英]get name of file in android kotlin

I have an Extention function in file with the name StringEx.kt.我在名为 StringEx.kt 的文件中有一个扩展函数。

StringEx.kt StringEx.kt

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

how can get the name and package of the file("StringEx.kt") in other class?如何在其他类中获取文件(“StringEx.kt”)的名称和包?

for example:例如:

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

here your not creating a class.在这里你没有创建一个类。 instead your just creating extension function and without class how can u get its package name.相反,您只是创建扩展函数而没有类,您如何获得它的包名称。 class "String" not belongs to "com.example" package类“String”不属于“com.example”包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM