Hide method / class using @hide in annotation

I am developing a library (jar) for android and I got into a situation where I want my class or method to be available only in my library, but not outside my library. Using a modifier will make the class available in this package, but I am in such a situation that this class cannot be used without the public modifier, because using the modifier will make it inaccessible in other packages that I do not want. For example, I have a class, let's say

 public class Globals { public static String thisDeviceAddress; public static String thisDeviceIP; public static String thisDeviceName = ""; } 

This class is available everywhere. The problem is that I want it to be available in my library, which I am developing, but not outside the library. I found out that using @hide annotation @hide solve the problem. For instance:

 /** * @hide */ class Globals { public static String thisDeviceAddress; public static String thisDeviceIP; public static String thisDeviceName = ""; } 

I knew a lot about this, but could not find a way to implement @hide . Just using @hide without a library didn't hide the class. So please provide me with the right guide. Any library to be used? Any way out to solve this problem?

+6
source share
1 answer

It is not possible to hide public classes and methods. This is a specification of the Java language, and you cannot break it.

0
source

Source: https://habr.com/ru/post/972371/


All Articles