一、备忘录相关类
package com.study.memento
class TencentVideo(var videoName: String, var videoUrl: String, var videoPlayProgress:Int){
override fun toString(): String {
return "TencentVideo(videoName='$videoName', videoUrl='$videoUrl', videoPlayProgress=$videoPlayProgress)"
}
}
package com.study.memento
import java.util.*
object TencentVideoMananger {
val tencentVideos = Stack<TencentVideo>()
fun addMemento(tencentVideo: TencentVideo) {
tencentVideos.push(tencentVideo)
}
fun getMemento() = tencentVideos.pop()
}
二、主程序调用
package com.study.memento
fun main() {
val tencentVideo00 = TencentVideo("大江大河", "http://大江大河", 23)
val tencentVideo01 = TencentVideo("白夜追凶", "http://白夜追凶", 33)
val tencentVideo02 = TencentVideo("精绝古城", "http://精绝古城", 13)
TencentVideoMananger.addMemento(tencentVideo00)
TencentVideoMananger.addMemento(tencentVideo01)
TencentVideoMananger.addMemento(tencentVideo02)
val memento02 = TencentVideoMananger.getMemento()
println(memento02)
val memento01 = TencentVideoMananger.getMemento()
println(memento01)
val memento00 = TencentVideoMananger.getMemento()
println(memento00)
}
三、运行结果