sealed classes and interfaces can't permit classes or records from sub packages
david Grajales
david.1993grajales at gmail.com
Sat Dec 28 04:14:41 UTC 2024
Hello Amber Team,
I’ve observed a counter intuitive behavior, and I’m unsure whether it’s
intentional or a potential issue.
Here’s the scenario:
1. I have a package named vehicles containing a *sealed interface*
called Vehicle.
2. Inside this vehicles package, I’ve created two sub-packages:
- land-vehicles
- water-vehicles
3. Each sub-package contains two records implementing the Vehicle
interface.
However, the compiler raises an error when I attempt this setup:
"A class is not allowed to extend or implement a sealed class from another
package."
This seems counterintuitive because all components are conceptually part of
the same package with the records merely placed in sub-packages for better
organization.
Here’s a textual representation of the package layout for reference:
vehicles/
├── Vehicle.java // Sealed interface
├── land-vehicles/
│ ├── Car.java // Record implementing Vehicle
│ ├── Motorcycle.java // Record implementing Vehicle
├── water-vehicles/
├── Boat.java // Record implementing Vehicle
├── Submarine.java // Record implementing Vehicle
Could you clarify whether this behavior is intended or a bug? If not, could
this be an area for potential improvement?
I am using openjdk 23.0.1
Thank you for your time and assistance!
Best regards and I hope you all have a nice new year.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20241227/f865cbd1/attachment.htm>
More information about the amber-dev
mailing list