Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin: Overload resolution ambiguity

Screenshot of the errorTrying to execute the below code :

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        Test().list.contains(1)
    }
}

public class Test {

    ArrayList<Integer> list;

    public ArrayList<Integer> getList() {
        return list;
    }
}

and compilation fails at Test().list.contains(1) with message :

Task :app:compileDebugKotlin FAILED e: /Users/sreejithcr/Documents/MyApplication/app/src/main/java/com/wxample/myapplication/MainActivity.kt: (13, 31): Overload resolution ambiguity: public open fun contains(@Nullable element: Int!): Boolean defined in java.util.ArrayList public open fun contains(@Nullable element: Int!): Boolean defined in java.util.ArrayList

What i understand is compiler finds 2 contains() with exact same signature and not sure which one to call.

gradle config :

ext.kotlin_version = '1.3.41'

classpath 'com.android.tools.build:gradle:3.4.2'

like image 262
sreejith cr Avatar asked Aug 08 '19 09:08

sreejith cr


1 Answers

It is an issue with Android Studios API 29 R2

https://issuetracker.google.com/issues/139041608#comment3

Go Tools -> SDK Manager -> Uninstall Android 9.+, then install it again as Google rolled back R2 so you'll be back to R1

like image 154
Sung Yang Avatar answered Sep 29 '22 03:09

Sung Yang