Java Language
ASecurityUse a sealed interface to make the allowed variants compiler-checked: ```java public sealed interface Payment permits Card, Cash, Voucher { } public record Card(String last4) implements Payment { } public record Cash() implements Payment { } public record Voucher(String code) implements Payment { } ``` Java 21 can then use an exhaustive pattern-matching switch: ```java static String describe(Payment payment) { return switch (payment) { case Card card -> "Card ending in " + card.last4(); case ...
- 584 stars
- 0 votes
- 0 copies
- 2 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 18 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill java-language --agent claude-codeAre you the author of Java Language?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-java-language-6d799948)Use a sealed interface to make the allowed variants compiler-checked:
```java
public sealed interface Payment
permits Card, Cash, Voucher {
}
public record Card(String last4) implements Payment {
}
public record Cash() implements Payment {
}
public record Voucher(String code) implements Payment {
}
```
Java 21 can then use an exhaustive pattern-matching switch:
```java
static String describe(Payment payment) {
return switch (payment) {
case Card card -> "Card ending in " + card.last4();
case Cash cash -> "Cash";
case Voucher voucher -> "Voucher " + voucher.code();
};
}
```
Because `Payment` is sealed, no other implementation can be passed as a `Payment`, and the compiler verifies that the switch handles every permitted variant. If the variants are only labels with no data or behavior, an `enum Payment { CARD, CASH, VOUCHER }` is the simpler choice.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-10.md
- trigger-11.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
- trigger-6.md
- trigger-7.md
- trigger-8.md
- trigger-9.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.