It is safe to use same classes from same modules in different layers

Alan Bateman alan.bateman at oracle.com
Wed Sep 11 13:52:35 UTC 2024



On 09/09/2024 09:55, PavelTurk wrote:
> Alan, could you please tell if it is technically possible to 
> substitute classes from another layer for an instance?
>
> I mean for situation with three layers I described :
> Bootlayer (module Core) is a main application
> - child layer A (module A, module Foo) is a plugin A
> - child layer B (module B, module Foo) is a plugin B.
>
> If class in Module B gets an instance of Foo (from module Foo) created 
> in Module A, is is possible to substitute its class with class
> from module Foo in layer B? I understand that currently it is not 
> possible. I ask if it is technically possible to implement it.
>
> The reason of my question is that real dynamic world is not as perfect 
> as JPMS assumption that if several layers use same module
> then this module must be present in their common parent layer.

This isn't really a module system issue. A-Foo and B-Foo are different 
types. They have the same class name "Foo" but have different defining 
class loaders. It would of course be possible for B to do the lookup and 
treat the returned object from the registry as an Object. To do 
something useful would need Foo to implement an interface that is 
visible and access to classes in the two module layers.

-Alan



More information about the jigsaw-dev mailing list