https://kotlinlang.org logo
#getting-started
Title
# getting-started
l

Lukasz Kalnik

03/13/2023, 12:11 PM
Is it allowed for a
public class
to implement an
internal interface
?
🚫 2
Ok, then I have some caching issue in my Android Studio because it doesn't show it as error...
image.png
I don't get a compile error somehow
Android Studio Giraffe (Canary)
m

mankin

03/13/2023, 12:54 PM
That is not an error, it's a warning. It's saying that the
MyClass
is never used elsewhere. Either use it somewhere or add
@Suppress("UNUSED")
on top of the class. Note: the warning can be there for a good reason, suppressing it only makes sense for libraries and you do not want to add test for that class.
l

Lukasz Kalnik

03/13/2023, 12:56 PM
The screenshot referred to my original question:
MyClass
should be underscored squiggly red, as it is a
public class
which extends an
internal interface
.
This should not compile
m

mankin

03/13/2023, 1:00 PM
internal
just means it's not visible outside the current module/project, if it's in the same module/project it's compile fine I would say (it might fail if you return/expose the interface as a type in some method)
l

Lukasz Kalnik

03/13/2023, 1:04 PM
I would think that you should not be able even to create such class, as a
public
class would then be able to expose an
internal
interface to outside code
m

mankin

03/13/2023, 1:14 PM
That's the whole point, you do not expose the interface (it's members) outside your module. https://discuss.kotlinlang.org/t/what-is-the-purpose-of-an-internal-interface/25384/12
l

Lukasz Kalnik

03/13/2023, 1:22 PM
Ah, so the methods of an
internal
interface are still publicly visible...
Thank you for the helpful link!
2 Views