Import Boolean from another class


Before: in java I had 2 Booleans directly under the main class of main activity, and they were imported to the preference activity
after converting to Kotlin
they went under companion object

//Main activity
class MainActivity : AppCompatActivity() {

    companion object {
        var bOne: Boolean? = true
        var bTwo: Boolean? = false

//Preference activity

they work in the main activity but their import doesn’t work anymore in the preferences activity class

when under companion object: Error Unresolved reference
when under the class directly: Error Cannot Import 'bOne', functions and properties can be imported only from packages or objects

going under companion object is legit but what should i do to fix the Unresolved reference error? sorry i’m new to kotlin


From kotlin try:


and from java, if needed, you would omit the “Companion”



i found that the problem was just that the automatically created companion object didn’t have a specific name to import to another place, so i called it companion (companion object companion{}) and everything worked

thanks for help


The name of the companion object can be omitted, in which case the name Companion will be used