Prefer CAST #( ) over ?=
WarningClean ABAP & Modern SyntaxQuickFix Ready#EC PREF_CASTRemote Enabled
Overview
Prefer modern CAST #( ) expression over ?=.
ATC Finding Message:
Prefer CAST #( ) constructor expression over ?= downcast
Rationale
The ?= downcast operator is legacy syntax and cannot be nested inside expressions. CAST #( ) returns a typed reference and can be used directly in call chains or constructor expressions. Use CAST for downcasts and let # infer the target type.
Non-Compliant
abap
lo_invoice ?= lo_document.Compliant
abap
lo_invoice = CAST #( lo_document ).Automated QuickFix
This rule provides an automated QuickFix directly in Eclipse ABAP Development Tools (ADT):
- Position the cursor on the flagged statement.
- Press Ctrl + 1 (Quick Assist).
- Select the automated refactoring to apply the clean syntax immediately.
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC PREF_CAST
" SAP CI_ prefix format:
... "#EC CI_PREF_CASTTechnical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_CAST - Implementation File: zcl_skylint_pref_cast.clas.abap