# 错误：记录类型上 'abstract' 和 'final' 修饰符的非法组合

- **ID:** `java/invalid-modifier-in-record`
- **领域:** java
- **类别:** compilation_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

Java 记录类型隐式是 final 的，不能是 abstract，因此同时声明 abstract 和 final 修饰符是非法操作。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Java 16+ | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## 解决方案

1. ```
   从记录声明中移除 'abstract' 和 'final' 修饰符。记录隐式是 final 的，不能是 abstract，只需声明：`public record MyRecord(int x) { }`
   ```
2. ```
   如果需要抽象，将记录转换为普通类，包含字段和方法，并手动实现 equals/hashCode/toString。
   ```
3. ```
   使用包含默认方法的接口，并由记录实现该接口，以实现抽象而不需要子类化。
   ```

## 无效尝试

- **Remove the 'final' modifier from the record declaration.** — Records are implicitly final; removing 'final' still leaves the record as final, but the abstract modifier remains, which is still illegal. (90% 失败率)
- **Add 'abstract' to a non-record class and implement the record's methods manually.** — This changes the design entirely and may break serialization or pattern matching that relies on the record's canonical constructor. (70% 失败率)
- **Use 'sealed' modifier instead of 'abstract' to allow subclassing.** — Sealed records are not supported in Java 17; the compiler will reject 'sealed' on records. (100% 失败率)
