Kt public property is private in java Anyone who c...
# announcements
j
Kt public property is private in java Anyone who could help ?
having following code
Copy code
@RunWith(AndroidJUnit4::class)
class XYZKt {
    @Rule
    val emojiTestRule = EmojiTestRule()

    @Test
    fun testZ() {
        println("X")
    }
}
after decompiling it's
Copy code
public final class XYZKt {
   @Rule
   @NotNull
   private final EmojiTestRule emojiTestRule = new EmojiTestRule();

   ...
}
And JUnit is failing, because that Rule field is private, is there a way how to force it to make it public ?
having same test written in java works just fine
m
Copy code
@get:Rule
val emojiTestRule = EmojiTestRule()
will not work fine?
it sames following code in Java.
Copy code
public final class XYZKt {
   @NotNull
   private final EmojiTestRule emojiTestRule = new EmojiTestRule();
   ...

   @Rule
   public EmojiTestRule getEmojiTestRule() {
        return emojiTestRule;
    }
}
d
Kotlin properties compile to a private field with a getter (and setter in case of
var
). Only getter and setter will have the visibility you specify. You can annotate your property with
@JvmField
to disable generation of getters/setters and only use a plain field.
2
j
ah thanks, that helps