You can place ClassA
and ClassB
in the same package (and ClassC
in the other) and use package-private
(or default
) access modifier for method FunctionA
.
This solution is the easiest and uses only JLS
specs (works for any language level and on any JVM
implementation):
Example 6.6-4. Access to Package-Access Fields, Methods, and Constructors
If none of the access modifiers public, protected, or private are specified, a class member or constructor has package access: it is accessible throughout the package that contains the declaration of the class in which the class member is declared, but the class member or constructor is not accessible in any other package.
Other ways to deal with your problem - reflection, code generation etc - is much more complex, buggy and slow
PS: also it is possible to leave method FunctionA
public and decompose your application into two modules. In the first module you should place ClassA
and ClassB
and in the second ClassC
. First module can use the second as a dependency but the second one shouldn't have an access to the first. This way is more suitable for complex applications and I recommended to use build tools such as Maven
or Gradle
to handle with such oriented dependency graphs (may be very tricky for large scale apps)