简体   繁体   English

Java 等效于 Kotlin class 与超类构造函数调用

[英]Java equivalent of Kotlin class with superclass constructor call

class FirstFragment : Fragment(R.layout.fragment_first){
}

I am new to android app development.我是 android 应用程序开发的新手。 I was trying to learn how to do a few things and I haven't studying Kotlin yet, how would I turn this small piece of code into the java class?我正在尝试学习如何做一些事情,但我还没有学习 Kotlin,如何将这小段代码变成 java class?

public class FirstFragment {
    
}

This is the Java version of your code:这是您的代码的 Java 版本:

public class FirstFragment extends Fragment {

    public FirstFragment() {
        super(R.layout.fragment_first);
    }

}

You inherit from Fragment with the extends keyboard and then you call the alternate constructor (the one with the layout parameter) from your default constructor.您使用extends键盘从Fragment继承,然后从默认构造函数调用备用构造函数(具有布局参数的构造函数)。

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

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