rewrite-migrate-java icon indicating copy to clipboard operation
rewrite-migrate-java copied to clipboard

Remove lombok.experimental.FieldDefaults

Open timtebeek opened this issue 2 years ago • 0 comments

@FieldDefaults is an experimental Lombok feature that along with a few sibling annotations allows users to forgo adding field modifiers to individual fields.

So

import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import lombok.experimental.NonFinal;
import lombok.experimental.PackagePrivate;

@FieldDefaults(makeFinal=true, level=AccessLevel.PRIVATE)
public class FieldDefaultsExample {
  public final int a;
  int b;
  @NonFinal int c;
  @PackagePrivate int d;
  
  FieldDefaultsExample() {
    a = 0;
    b = 0;
    d = 0;
  }
}

Becomes

public class FieldDefaultsExample {
  public final int a;
  private final int b;
  private int c;
  final int d;
  
  FieldDefaultsExample() {
    a = 0;
    b = 0;
    d = 0;
  }
}

which if you were to ask me does not improve readability for this small sample.

Given that it's an experimental feature, with an uncertain future given the last update ("this feature will not be leaving experimental in its current state"), there's bound to be an audience for removing these annotations with their one to one replacement modifiers.

I've placed the issue here as we have other lombok recipes/issues in this repository, and newer versions of Lombok or Java might have it make sense to be part of rewrite-migrate-java.

timtebeek avatar Jan 26 '23 10:01 timtebeek