Suppose you have module A and moduleB. ModuleA defines an interface (for example, for a service), and ModuleB has a specific class that implements the interface (provides a service).
Now, if the interface has a default method and you call it in a class in module B (from another module), should this call be made inside module A or module B? Apparently, this is from module A ... what is the rationale?
Example: suppose you have code that does this:
InputStream is = this.getClass().getResourceAsStream(fullPath);
if this code is in the service implementation in module B, the stream will be open. But if the code lies in the default method in module A, then when you call the service on module B, you will need to have an “open” resource in module B (therefore, it seems that the call believes that it is from the “external” module B).
I would like to read about the reason for this.
thanks
editing my question with an example. Suppose you have this code in a module:
public interface PropertiesProvider {
public default Properties get(String domain) {
Class clazz =this.getClass();
System.out.println(" CLASS " +clazz);
InputStream is = clazz.getResourceAsStream(domain) ;
if (is != null) {
Properties props = new Properties();
try {
props.load(is);
return props;
} catch (IOException e) {
}
}
return null;
}
}
and in module B
public class PropertiesProviderImpl implements PropertiesProvider {}
if you call a service from module A, the call from the PropertiesProviderImpl class is tracked; it finds a resource but does not load it if it is not "open"
if you copy the code into PropertiesProviderImpl, the calls are traced back to the same class that finds the ressource and loads it, even if it is not "open"
, : , ?
( , - )