Sealed classes actually need `permits` if are in the same package?

I'm using Java 24. Sealed classes need permits if they and the inheritors are in the same package? I would to do it without specify the classes in my interface, if it's possible automatically detect the inheritors in the package.
package com.latteIceCream.latte.dto;

public sealed interface DTO<ID> { ID altId(); } Sealed type DTO lacks a permit clause and no type from the same compilator unit declares DTO as its direct supertype
package com.latteIceCream.latte.dto;

public sealed interface DTO<ID> { ID altId(); } Sealed type DTO lacks a permit clause and no type from the same compilator unit declares DTO as its direct supertype
package com.latteIceCream.latte.dto;

public record ProductDTO(String name) implements DTO<String> The type ProductDTO that implements the sealed interface DTO<String> should be a permitted subtype of DTO<String>

{ @Override public String altId() { return name; } }
package com.latteIceCream.latte.dto;

public record ProductDTO(String name) implements DTO<String> The type ProductDTO that implements the sealed interface DTO<String> should be a permitted subtype of DTO<String>

{ @Override public String altId() { return name; } }
I heard it can pick the classes in the package in common as permitted, I hope is true 🫠.
1 Reply
JavaBot
JavaBot•4mo ago
⌛ This post has been reserved for your question.
Hey @Franscis123$#! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?