Hiding a method from a 3rd party jar

I am using a 3rd party jar which has a method lets say - “RemoteFunction”.
I have a wrapper around this function in my project (in package.scala). lets say - “WrapperRemoteFunction”.
I want to make sure that all contributing members always use “WrapperRemoteFunction” instead of “RemoteFunction”.
Is there a way to hide “RemoteFunction” from my project?


You can’t hide methods, but you can hide types (e.g. classes, traits).

If you put two types of the same name (full name, with packages) on the
classpath, the one that comes first will hide the one that comes second.
This hiding will be absolute, for all code, even for code that is part of
the same library.

If you want the type to be hidden from some code, but not from other
code, then you need a custom class loader.

 Best, Oliver

Alternatively, you could consider including a rule to enforce this in a code style check. For example I think it could be possible with http://www.scalastyle.org/rules-0.8.0.html#org_scalastyle_file_RegexChecker

Agree, a style check is going to be the easiest answer. The language doesn’t provide a way to do this. There are all kinds of complicated tricks you can do but these are likely to lead to suffering. Keep it simple.

1 Like