Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda