I have a few functions that would be peffect as ex...
# codereview
m
I have a few functions that would be peffect as extension functions. BUT they are only relevant in a specific context (feature package) and I do not want to pollute the whole public namespace of their receiver classes. For context: I’m currently using Soong (not Gradle), and I can’t simple create a module for the feature, so
internal
is not an option. What is the best practice for those cases? Currently, I’m considering to introduce a
object Utils
to hold the functions and limit visibility to reduce pollution but I don’t like it. Maybe there is an alternative approach that I’m not aware of.
I’m not sure if there is a way to do that, but if I could create extension functions that do not appear in the auto-complete but could still be used, that should be good enough I guess to reduce pollution… I guess. 🤔
l
An ugly workaround might be to
@Deprecated
it with
Warning
setting. It will be deprioritized on suggestions and still usable
m
FYI, my current solution is: 1. Wrapped all extensions in an object. IDEA shows it as last in the auto-complete, it seems. 2. Added an
InternalApi
annotation as an error so people at least is warned if they try to use it.
e
if you can modify the build system to add the right
-Xfriend-paths
to the compiler args of dependent modules, you can use
internal