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

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

问题描述

我可以用Kotlin语言替代Inner static Class的哪些替代方法?如果没有,当我需要在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天全站免登陆