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

216
Visualizações
'public' function exposes its 'public/*package*/' parameter type SolarEdgeException

I have the following Java and Kotlin classes:

package nl.friesoft.solaredgenotifier;

class SolarEdgeException extends Exception {
    public SolarEdgeException(String s)  {
        super(s);
    }
}



package nl.friesoft.solaredgenotifier

class SiteStorage(context: Context): ISolarEdgeListener {
    override fun onError(site: Site?, exception: SolarEdgeException?) {
    }
}

And I get this compilation error:

'public' function exposes its 'public/package/' parameter type SolarEdgeException

Both classes are in the same package, so why doesn't this compile?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Classes by default in Kotlin are public, so every member/function is exposed to the outer world. Contrarily, in Java the default visibility, that is omitting a visibility keyword such as public, protected or private, is package-private.

SolarEdgeException is package-private, while its user SiteStorage is entirely public.

That means a user of SiteStorage cannot catch or use your exception at all.


Unfortunately Kotlin doesn't have the concept of package-private, because packages aren't managed the same way as in Java.

The best you can have is internal, which means the definition is visibile to the entire module.
I'd say, in this case, make SolarEdgeException a public class, maintaining the constructor as package-private.

There is a forum thread on the package-private visibility for Kotlin, it's an interesting read.
kotlin-to-support-package-protected-visibility

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