Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm making an SDK and I'm trying to separate classes to different packages, those classes use some other shared classes. The issue is if I made the shared classes public everyone will be able to see them, not only my classes. What's the right way to make them only accessible by my application?

Example :


Package a MyClass1

Package b MyClass2

Package c public MySharedClass


Because c is public MySharedClass will be able to access it, but the issue is that it will also will be visible to the world, how could I prevent that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
221 views
Welcome To Ask or Share your Answers For Others

1 Answer

Create a package that is documented as an internal package, not to be used by clients.

There is no way in Java to make a class public only for certain packages: It either is public for everyone or package-private (public only in the declared package).

I think there's a proposal for modules to allow better control in the visibility of classes, but we'll have to wait, at least, for Java 8.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...