我有一个扩展AppCompatActivity的试用活动类Main活动。在文档中,AppCompatActivity继承了方法onRequestPermissionsResult,当我试图重写上述方法onRequestPermissionsResult时,会出现此错误。
“错误:(95,5) 'onRequestPermissionsResult‘没有覆盖任何东西”
class MainActivity : AppCompatActivity(), ConnectionCallbacks, OnConnectionFailedListener{
//I didnt include the other functions in the interfaces, suffice to say i have already added them in the original
override fun onRequestPermissionsResult(requestCode : Int , permissions: Array<String>, grantResults: Array<Int>){
println("SHOULD HAVE THIS FUNCTION")
}
}发布于 2017-07-23 14:39:58
Kotlin Array<Int>映射到Integer[],IntArray映射到int[],它们是Java中不同的数组类型。你可以在科特林看到更远的映射类型。
AppCompatActivity#onRequestPermissionsResult方法签名是:
override fun onRequestPermissionsResult(requestCode : Int ,
permissions: Array<String>,
grantResults: IntArray){
// it is IntArray rather than Array<Int> ---^
TODO()
}而不是:
override fun onRequestPermissionsResult(requestCode : Int ,
permissions: Array<String>,
grantResults: Array<Int>){
TODO()
}注意:如果api承诺它的参数永远不会是null,比如onRequestPermissionsResult,那么您可以使用IntArray来简化参数的使用。否则,您应该使用IntArray?代替。
--如果不想知道Kotlin中的所有映射类型,还有一种方法可以使您快速覆盖超类方法。首先,将光标放入类中,然后按CTRL+O选择要覆盖的方法。例如:
class MainActivity : AppCompatActivity(),
ConnectionCallbacks,
OnConnectionFailedListener{
// put the cursor here, press `CTRL+O` to select which method you want to override
}https://stackoverflow.com/questions/45266264
复制相似问题