Steven Wexler
Steven Wexler

Reputation: 17279

Java warn / disallow method in specific package

I created a wrapper around Log.i.

public class MyLog {
  public static int i(String tag, String message) {
    //Do Stuff
    return Log.i(tag, message);
  }
}

Now I'd like all my consumers com.myapp.package1, com.myapp.package2, etc. to use MyLog.i instead of Log.i. Currently, we're just enforcing this by conventions and documentation. Are there more aggressive programatic ways to discourage or disable developers from calling Log.i from within certain packages?

Upvotes: 0

Views: 36

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93542

Not within the language itself. THis is something better done by either your build system or your source control system. A lint rule would work, with your build system set to error out or your source control set to reject diffs that fail the rule.

Upvotes: 2

Related Questions