4

I have the following code:

class ViewHolder(itemView: View, val ui: ViewUI)

I don't want that the field ui have a getter, but kotlin is generating it by default since it is a val defined in the constructor.

In the properties and fields document I found that I can generate a private getter with the following code

var setterVisibility: String = "abc"
    private set

But I can't find a way to do this in the constructor definition

1 Answer 1

9

You can make the entire property private in the constructor, that way it will only be accessible inside the class:

class ViewHolder(itemView: View, private val ui: ViewUI)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.