https://kotlinlang.org logo
#announcements
Title
# announcements
v

ValV

07/09/2019, 8:08 AM
I have faced some weird thing from Java - method reference operator on an object like so:
RegexCompleter("SomeCoolRegexString", myHashMap::get)
. I've read from stackoverflow that Kotlin does not support method reference on objects. How to convert to Kotlin?
i

igor.wojda

07/09/2019, 8:32 AM
hmm…Below is the example of object (and class) method references. Hmm - does it cover you case?
Copy code
fun main(args: Array<String>) {
    val classFooMethodReference = Foo.Companion::doSth
    
    val companionFooMethodReference = Foo::companion::classdoSth
    
    val foo = Foo()
    val instanceFooMethodReference = foo::doSth
    
    val objectBarMethodReference = Bar::doSth
}

class Foo() {
    companion object {
        fun doSth() {
        
    	}
    }
    
    fun doSth() {
        
    }
}

object Bar {
    fun doSth() {
        
    }
}
v

ValV

07/09/2019, 9:15 AM
Looks like it's ok. I need to resolve all the preceeding errors in the code 🙂
i

ilya.gorbunov

07/09/2019, 2:21 PM
Could you share that link to stackoverflow where you have read it?
i

igor.wojda

07/10/2019, 10:06 AM
@ValV I think Ilya meant link to stack overflow post (with this information), not your code
I have just missed icon while reading
i

ilya.gorbunov

07/10/2019, 11:09 AM
Seems that the answer is outdated since Kotlin 1.1, when the bound callable references were introduced https://kotlinlang.org/docs/reference/reflection.html#bound-function-and-property-references-since-11
v

ValV

07/10/2019, 11:52 PM
Ah, I see
3 Views