Kotlin密封类

一、密封类非常简单

package net.println.kotlin.chapter4

import net.println.kotlin.chapter4.objects.Player
import java.text.FieldPosition

/**
 * @author:wangdong
 * @description:Sealed类的子类只能定义在它的类里面,或者与他在同一个文件里
 */
/**定义一个播放的类*/
sealed class PlayerCmd{
    //定义一个内部类,继承PlayerCmd
    //播放
    class Play(val url: String,val position: Long = 0):PlayerCmd()

    //快进
    class Seek(val position: Long): PlayerCmd()

    //暂停
    class Pause: PlayerCmd()

    //继续
    class Resume: PlayerCmd()

    //停止
    class Stop: PlayerCmd()

}

/**枚举类*/
enum class PlayerState{
    IDLE,PAUSE,PLAYING
}

结束啦

你可能感兴趣的:(Kotlin语言)