-1

I've just noticed two different libraries sharing paths. Example is as follows. enter image description here There are two seperate packages - spring-boot-actuator, spring-boot-actuator-autoconfigure.

enter image description here

Packages included in these libraries share the same parent package or package path. I can't imagine the things under the hood. Wouldn't this lead to linking errors?

Now.Zero
  • 1,147
  • 1
  • 12
  • 23
  • 1
    Not clear what you are asking for. Package x.y.z is NOT the same as x.y.z.p ... so the fact that x.y.z has classes in one library, and x.y.z.p has classes in another one should really be not a problem. Also note: it for isn't ideal, but there isn't necessarily a problem when two different projects/library use the same x.y.z package. It only becomes complicted when you have two different classes BOTh named x.y.z.A ... then things become messy. – GhostCat Jun 22 '22 at 10:20
  • 2
    You don't seem surprised that both start with `org.springframework` though. Why would this be different? – Federico klez Culloca Jun 22 '22 at 10:21

1 Answers1

0

Package a.b.c is different from a.b.c.d, there is no hierarchical relationship between any two packages in Java, as we may assume.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Roshan
  • 667
  • 1
  • 5
  • 15
  • 1
    *"there is no hierarchical relationship between any two packages in Java"* uhm... I'd take issue with this statement as written. Can you please clarify what you mean? – Federico klez Culloca Jun 22 '22 at 10:31
  • A parent child relationship nor dependency doesn't exist between packages, that could interfere with Class loading , but from Software design perspective hierarchies are needed for ease of development. – Roshan Jun 22 '22 at 10:41
  • 2
    @FedericoklezCulloca As far as Java is concerned, package "x.y.z" is not contained in package "x.y". The fact that on the filesystem there might be a hierarchical relation does not translate to a hierarchical relation in Java itself. The naming structure is hierarchical (JLS 17 chapter 7), but packages themself are not. – Mark Rotteveel Jun 22 '22 at 10:49
  • 2
    Specifically, [JLS 17 section 7.1](https://docs.oracle.com/javase/specs/jls/se17/html/jls-7.html#jls-7.1) says: _"The hierarchical naming structure for packages is intended to be convenient for organizing related packages in a conventional manner, but has no significance in itself other than the prohibition against a package having a subpackage with the same simple name as a top level class or interface (§7.6) declared in that package. "_ – Mark Rotteveel Jun 22 '22 at 10:54
  • @MarkRotteveel Explained it well. – Roshan Jun 22 '22 at 10:57