R
Royan
Imagine I have two classes in two packages:
package org.fooA;
class A {
}
package org.fooZ;
public class Z {
public Z() {
//I need to instantiate class A here
}
}
I have two conditions that I want to meet
1) I want to hide class A from an end user, someone who is going to
use my code, so I don't want this person to instantiate class A and
make use of its functionality.
2) I want to instantiate class A from my own class Z that resides in
another package
The problem is that whatever I think about does not meet both
conditions. For instance if class A is defined as "package-private"
class i can not use it myself, if it is public it is not hidden and
can be instantiated from any part of the code.
package org.fooA;
class A {
}
package org.fooZ;
public class Z {
public Z() {
//I need to instantiate class A here
}
}
I have two conditions that I want to meet
1) I want to hide class A from an end user, someone who is going to
use my code, so I don't want this person to instantiate class A and
make use of its functionality.
2) I want to instantiate class A from my own class Z that resides in
another package
The problem is that whatever I think about does not meet both
conditions. For instance if class A is defined as "package-private"
class i can not use it myself, if it is public it is not hidden and
can be instantiated from any part of the code.