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

musachy

07/10/2017, 5:32 PM
how is property ambiguity resolved? Cant find any info on that
k

karelpeeters

07/10/2017, 6:51 PM
musachy: Can you perhaps give some examples? Generally the "closest" property is used.
m

musachy

07/10/2017, 7:35 PM
Hi Karel, sorry about that
so if I have a class with a protected property "x" and I have a child class that also defines "x". The compiler rightly complains about it.
k

karelpeeters

07/10/2017, 7:35 PM
No problem, just try not do do it in the future simple smile. It's annoying if people from both channels start helping at once.
m

musachy

07/10/2017, 7:36 PM
I cant seem to find any info on how to tell the compiler which one to use
k

karelpeeters

07/10/2017, 7:37 PM
Can you post some example code.?
m

musachy

07/10/2017, 7:40 PM
hum. I was writing an example and just realized that in pure Kotlin it doesnt happen. As you need to "override" the parent property. It is between base Java class and child Kotlin
k

karelpeeters

07/10/2017, 7:40 PM
A mixed example is fine too 😄
m

musachy

07/10/2017, 7:43 PM
Java base class:
import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Base { protected Logger logger = LoggerFactory.getLogger("Base"); }
Kotlin child class: import org.slf4j.LoggerFactory class Child: Base() { private val logger = LoggerFactory.getLogger("Child") fun test() { logger.debug("ouch") } }
k

karelpeeters

07/10/2017, 7:45 PM
Okay and logger.debug uses the Child one, right?
m

musachy

07/10/2017, 7:45 PM
The compiler will complain about " logger.debug("ouch")"
yes
k

karelpeeters

07/10/2017, 7:50 PM
Hmm, interesting one.
You can get the
Base
logger like this:
(this as Base).logger.debug("ouch")
m

musachy

07/10/2017, 7:52 PM
ah!
didn't think of that
k

karelpeeters

07/10/2017, 7:52 PM
But you need the Child one, right?
m

musachy

07/10/2017, 7:52 PM
well, I actually need the child one 🙂
k

karelpeeters

07/10/2017, 7:54 PM
Tbh I don't think there's actually a way to do this.
But for now you can just pick another variable name 🙂
m

musachy

07/10/2017, 7:59 PM
fyi
I did used a different name, but it was a splinter in my mind to find the "right" solution. Thanks for the help!
k

karelpeeters

07/10/2017, 8:00 PM
A quick tip for using youtrack: format your code like this:
{code:lang=kotlin} actual code {code}
m

musachy

07/10/2017, 8:03 PM
fixed. that helps.