I have a JakartaEE java webapp (say project A) and a java library project/jar (say project B). Project B is imported in Project A as a dependency via maven.
I have a singleton instance of a class (say obj1) injected into a class (say Class2) in Project A via Guice. Project B does not import nor know about the class of obj1 (i.e. trying to add an instance of obj1's class in Project B leads to a compilation error).
I have defined the following functional interface in Class2 of Project A:
public final Function<String,InputStream> func = str -> {
return obj1.get(str);
};
I pass the variable func
to a method in Project B and then call apply on it there.
I am confused to as to how calling apply
on func
in Project B works given the fact that obj1's class is technically not visible in Project B.
I guess I'm trying to understand how this works internally/after compilation. Thanks.