Kotlin 中的静态内部类 [英] Static Inner Class in Kotlin

查看:45
本文介绍了Kotlin 中的静态内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 Kotlin 语言中使用什么替代 内部静态类(如果存在)?如果没有,当我需要在 Kotlin 中使用 static class 时如何解决这个问题?请参阅下面的代码示例:

What alternative to an Inner static Class can I use in Kotlin Language, if it exists? If not, how can I solve this problem when I need to use a static class in Kotlin? See code example below:

 inner class GeoTask : AsyncTask<Util, Util, Unit>() {

    override fun doInBackground(vararg p0: Util?) {

        LocationUtil(this@DisplayMembers).startLocationUpdates()
    }
}

我搜索了很多,没有找到任何东西,在此先感谢您.

I've searched a lot, haven't found anything, Thank you very much in advance.

推荐答案

只需省略 Kotlin 中的 inner.

Just omit the inner in Kotlin.

内部类(持有对外部对象的引用)

Java:

class A {
    class B {
    ...
    }
}

科特林:

class A {
    inner class B {
    ...
    }
}

静态内部类又名嵌套类(不引用外部对象)

Java:

class A {
    static class B {
    ...
    }
}

科特林:

class A {
    class B {
    ...
    }
}

这篇关于Kotlin 中的静态内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆