Skip to content

[java] New rule: CStyleArrayDeclaration #7026

Closed

Description

@zbynek

Proposed Rule Name: ArrayTypeStyle CStyleArrayDeclaration

Proposed Category: Code Style

Description:
Prefer Java style declaration of arrays as int[] numbers over C-style int numbers[]. The rule should apply both to fields and methods.

Code Sample:

class Numbers {
  double doubles[]; // bad
  int[] ints; // good
  double getDoubles()[] { // bad
    return new double[] { 1.0 };
  }

  int[] getInts() { // good
    return new int[] { 1 };
  }
}

Possible Properties:

None.


This can be already achieved using a trivial XPath rule //VariableId/ArrayDimensions|//MethodDeclaration/ArrayDimensions, but it would be nice to have it in PMD directly.

Activity

  1. added
    a:new-rule
    on Sep 2, 2026
  2. pzygielo commented on Sep 2, 2026

    @pzygielo
    Contributor

    Would it also catch the case for methods?

    class P {
      double getDoubles()[] { // bad
        return new double[] { 1.0 };
      }
    
      int[] getInts() { // good
        return new int[] { 1 };
      }
    }
  3. zbynek commented on Sep 2, 2026

    @zbynek
    ContributorAuthor
  4. changed the title [-][java] new rule: ArraySizeAfterName[/-] [+][java] new rule: ArrayTypeStyle[/+] on Sep 4, 2026
  5. linked a pull request that will close this issue[java] New rule: CStyleArrayDeclaration #7031on Sep 4, 2026
  6. changed the title [-][java] new rule: ArrayTypeStyle[/-] [+][java] new rule: CStyleArrayDeclaration[/+] on Sep 5, 2026
  7. changed the title [-][java] new rule: CStyleArrayDeclaration[/-] [+][java] New rule: CStyleArrayDeclaration[/+] on Sep 8, 2026
  8. added this to the 7.28.0 milestone on Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a:new-rule

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions