Kotlin與Java不相容的情況
阿新 • • 發佈:2019-02-02
定義一個Java的interface:
public interface IJavaTest { void test(int param); void test(Integer param); void test(float param); void test(Float param); }
用Kotlin實現這個Java interface,用AS的自動匯入如下:
class KotlinTest : IJavaTest { override fun test(param: Int) { TODO("not implemented") //To change body of created functions use File | Settings | File Templates.} override fun test(param: Int?) { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } override fun test(param: Float) { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } override fun test(param: Float?) {TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } }
Java把基本資料型別和包裝類引數定義看做是方法過載,而Kotlin認為這兩個Java方法是一樣的。