1
votes

Why can't we use protected access modifier in Singleton class for Kotlin . We can use the protected access modifier in Java class but when it comes to kotlin , this does not work out .

2

2 Answers

3
votes

In Kotlin you cannot inherit from a singleton object, that's why protected modifier is useless, since protected modifier opens functions/properties for this class and subclasses only.

2
votes

You can't inherit from an object in Kotlin, so protected modifier does not make any sense. In Java, there is no such thing as singleton at language level, it's just a class with some specific logic