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

70
Visualizações
how to set custom return type nullable in kotlin

I made a personal data type "email" how can I make this type nullable in value.

For example.

private lateinit var a: email?

or

fun makeEmailAddress(a: String): email? {
   // TODO
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

lateinit var uses nulls behind the scenes to represent the uninitialized value, so they cannot be of nullable types from the point of view of the program. That said, this limitation is in general not a problem because most of the time the point of using lateinit var is so that you can use non-null types while still delaying initialization.

If you need a nullable property, you can simply drop the lateinit modifier and initialize it to null when declaring it:

private var a: Email? = null

For the function declaration, the return type Email? should just work:

fun makeEmailAddress(a: String): Email? {
   // return whatever you need here, either null or an Email instance
}

Note that types are capitalized in Kotlin by convention, so I suggest you rename email to Email (I used the capitalized version in the sample code above).

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