Skip to content

Use pattern matching instead of type casting #2741

Closed
@junghoon-vans

Description

@junghoon-vans

JEP 394: Pattern Matching for instanceof allows to avoid direct typecasting.

Example

AS-IS

if (owner instanceof ElasticsearchPersistentEntity) {
 	return ((ElasticsearchPersistentEntity<?>) owner).getFieldNamingStrategy();
 }

TO-BE

if (owner instanceof ElasticsearchPersistentEntity<?> persistentEntity) {
 	return persistentEntity.getFieldNamingStrategy();
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions