# error: illegal combination of modifiers: 'abstract' and 'final' for a record

- **ID:** `java/invalid-modifier-in-record`
- **Domain:** java
- **Category:** compilation_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

Java records are implicitly final and cannot be abstract, so declaring a record with both abstract and final modifiers is illegal.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Java 16+ | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## Workarounds

1. **Remove both 'abstract' and 'final' from the record declaration. A record is implicitly final and cannot be abstract, so simply declare: `public record MyRecord(int x) { }`** (95% success)
   ```
   Remove both 'abstract' and 'final' from the record declaration. A record is implicitly final and cannot be abstract, so simply declare: `public record MyRecord(int x) { }`
   ```
2. **If you need abstraction, convert the record to a regular class with fields and methods, and implement equals/hashCode/toString manually.** (85% success)
   ```
   If you need abstraction, convert the record to a regular class with fields and methods, and implement equals/hashCode/toString manually.
   ```
3. **Use an interface with default methods and a record implementing that interface to achieve abstraction without subclassing.** (80% success)
   ```
   Use an interface with default methods and a record implementing that interface to achieve abstraction without subclassing.
   ```

## Dead Ends

- **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% fail)
- **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% fail)
- **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% fail)
