1.泛型继承
open abstract class BaseAbstractPresenter<T : IBaseView?> : BasePresenter {
var mView: T? = null
constructor(mView: T) {
this.mView = mView
}
override fun detachView() {
mView = null
}
}
open abstract class DialogBaseActivity<T : BaseAbstractPresenter<*>> : NormalBaseActivity(), IBaseView {
lateinit var mPresenter: T
abstract fun createPresenter(): T
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mPresenter = createPresenter()
}
override fun detachView() {
mPresenter?.detachView()
}
override fun onDestroy() {
super.onDestroy()
detachView()
}
}
BaseAbstractPresenter不能指定明确的泛型类型用*代替,不能使用Any
2.Gson转换String转bean