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

177
Vistas
Can I always use private set instead of private val in kotlin?

I read some kotlin project samples code, I find many author like to Code A.

I think Code B is more simpler.

1: Is Code B good way?

2: Can I always use private set intead of private val in Android Studio?

Code A

private val _uiState = MutableStateFlow(InterestsUiState(loading = true))
val uiState: StateFlow<InterestsUiState> = _uiState.asStateFlow()

Code B

var uiState = MutableStateFlow(InterestsUiState(loading = true))
    private set
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

A, B are not the same code.

In code A, define another variable as StateFlow is preventing to change value in StateFlow from out of class.

In code B, you can update value in StateFlow from out of class. Because you can refer MutableStateFlow.

Mutating state variable itself and Mutating state in StateFlow is different.

Observer observing StateFlow is received event when value in StateFlow is change but change StateFlow itself.

In other word, you should use code A for prevent to unexpected mutating from outer

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