```class SomeClass { private InnerClass innerC...
# announcements
m
Copy code
class SomeClass {
    private InnerClass innerClass = new InnerClass();

void foo() {
    String name = innerClass.name;
}

private static class InnerClass {
        private String name = "Murali";
}
}
When i convert this code into kotlin using kotlin converter in IDEA i got an error at innerClass.name showing the name is private. But that works fine in Java. Please show me how to achieve the same in kotlin!
p
Surround your code with triple backticks, please.
m
I did it @Pavlo Liapota! Thanks!
👍 1
a
What is the conversion result?
g
This code is incorrect. You forgot
}
and it’s not clear where this
}
should be, before foo, before InnerClass or on the end
also the is no keyword class before
InnerClass
so in general this code is wrong, so try to fix it first in java and than convert to Kotlin
But I see what you mean, if you have this original code:
Copy code
class SomeClass {
    private InnerClass innerClass = new InnerClass();

    void foo() {
        String name = innerClass.name;
    }

    private static class InnerClass {
        private String name = "Murali";
    }
}
it will not work in Kotlin, because Kotlin doesn’t generate accessor for private field
name
As workaround just make it non-private. Class already private so can be used only by SomeClass, so it doesn’t break encapsulation in this case
👆 2
m
I edited it @gildor! Actually it was a typing error! But yeah the code in java was fine and when i converted it( it was syntactically correct) i got error at property access!
Thanks @gildor!