Unresolved reference error while calling add method in Kotlin Set interface -


if use set interface reference , try call add method unresolved reference error:

  fun main(args : array<string>) {     val set = hashset<integer>()     set.add(integer(1)) //ok      val seti : set<integer> = hashset<integer>()     seti.add(integer(2)) //failing: unresolved reference add**   } 

i don't understand behaivour. java set interface has add method , expected kotlin 1 extended version , not had less methods.

pd1: same error in idea ide or building gradle. pd2: using kotlin 1.0.0-beta-4584

kotlin seperates java's set interface 2 interfaces: set , mutableset. latter interface declares mutating methods such add method you're looking for.

generally, interfaces such mutableset extend set interface, , implementations hashset implement mutableset interface. set interface can used pass around read-only instance, avoid common bugs happening.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -