In Java, by leaving the access modifier as the default one (blank), the fields becomes accessible to only members in the same package. However, this is not preventing others from declaring their classes in the same package and then accessing the "default" fields from there.
Is there a way in Java to make fields C# equivalent to internal
. That is, when I build my library (JAR file), there's no way others can access those fields from outside the JAR? Even when declaring their classes in the same package as my classes.
Here is my declaration in my library:
package com.my.package;
class MyRestrictedClass{
}
What I'm trying to prevent is the user of my library to do from their project with my jar added to their build path something like:
package com.my.package; //Add their class to my package
public class DeveloperClass{
public void main(){
MyRestrictedClass foo = new MyRestrictedClass();
}
}