Java: Subpackage visibility?

后端 未结 9 1462
予麋鹿
予麋鹿 2020-11-29 02:06

I have two packages in my project: odp.proj and odp.proj.test. There are certain methods that I want to be visible only to the classes in these two

9条回答
  •  北海茫月
    2020-11-29 02:42

    EDIT: If there is no concept of a subpackage in Java, is there any way around this? I have certain methods that I want to be available only to testers and other members of that package.

    It probably depends a bit on your motives for not displaying them but if the only reason is that you don't want to pollute the public interface with the things intended only for testing (or some other internal thing) I would put the methods in a separate public interface and have the consumers of the "hidden" methods use that interface. It will not stop others from using the interface but I see no reason why you should.

    For unit tests, and if it is possible without rewriting the lot, follow the suggestions to use the same package.

提交回复
热议问题