Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
Why is this Kotlin class property not public?

I've got an app that is regularly using classes written in Kotlin which are accessed by other classes and their methods written in Java.

I had the following class in Java:

public class MyDataClass {
    public String color;
    public String action;
}

I've decided to move it to Kotlin:

class MyDataClass {
    var color: String = ""
    var action: String = ""
}

Upon recompiling, I'm now getting the following error message:

/myPath/MyApp.java:[93,20] color has private access in myapp.command.MyDataClass

I get a similar error for action.

Per the Kotlin reference, the default visibility modifier for class and properties (and a bunch of other things) is public.

Why are these properties being treated as private?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Because it's a private field with a public getter and a public setter. You cannot access fields directly in Kotlin, everything is properties.

Refer to: https://kotlinlang.org/docs/reference/properties.html#backing-fields

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda