2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Javaメソッド修飾子の順序を探してみました

Posted at
  • 過去に執筆した記事を日本語に書き写しました
  • 翻訳機を使用しているため、誤字や不自然な表現があるかもしれません

はじめに

突然、フィールド宣言における修飾子(modifier)の宣言順序が気になり、調べてみました。

普段、私は習慣として

public static final String test = "hello";

と書いていたのですが、突然疑問に思うようになりました。

final static public String test = "hello";

こうしても良いのではないかと思い、一度調べてみました。

Java 17公式ドキュメント

8.4.3 Method Modifiers

image.png

MethodModifier(メソッド修飾子)のパートには、以下のように記載されています。

@Anotaition, public, protected, private
abstract static final synchronized native strictfp
If two or more (distinct) method modifiers appear in a method declaration, it is customary,
though not required, that they appear in the order consistent with that shown above in the
production for MethodModifier.

複数の(異なる)メソッド修飾子がメソッド宣言に現れる場合、慣例として(必須ではありませんが)上記のMethodModifier規則で示された順序に従って記述することが望ましいです。

推奨事項

推奨される記述順序は以下の通りです:

  • @ Annotation
  • public
  • protected
  • private
  • abstract
  • static
  • final
  • synchronized
  • native
  • strictfp

上記の順序に従って記述することが望ましいです。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?