Kotlin 的 file & class

1. 定义一个file 文件, 里面的方法全部都是全局静态的.

@file: JvmName("WeddingDatePickerDialog")   // 文件名可以自定义, 方便java文件调用

package com.xogrp.planner.pickers

import android.view.View

import com.google.android.material.datepicker.*

import com.xogrp.style.R

fun getDatePickerDialog(

styleRes: Int = R.style.TheKnotDataPickerTheme,

        defaultSelection: Long = MaterialDatePicker.todayInUtcMilliseconds(),

        minDate: Long = -1,

        maxDate: Long = -1,

        onNegativeAction: (() -> Unit)? =null,

        onPositiveAction: ((Long) -> Unit)? =null

): MaterialDatePicker { }


================================================================

2. 定义一个Class 文件

package com.xogrp.planner.pickers

import android.view.View

import com.google.android.material.datepicker.*

import com.xogrp.style.R

class WeddingDatePickerDialog  {

companion object {

        fun getDatePickerDialog(

                styleRes: Int = R.style.TheKnotDataPickerTheme,

                defaultSelection: Long = MaterialDatePicker.todayInUtcMilliseconds(),

                minDate: Long = -1,

                maxDate: Long = -1,

                onNegativeAction: (() -> Unit)? =null,

                onPositiveAction: ((Long) -> Unit)? =null

        ): MaterialDatePicker { }

}

}

推荐阅读更多精彩内容