修饰符Java中的关键字顺序 [英] Modifier Keyword order in Java

查看:782
本文介绍了修饰符Java中的关键字顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我在Java中编写方法时,使用的关键字多于public + void,每次我以另一种方式写它。有时静态公共无效有时是公共静态无效等。

Every time I write method in Java with more keywords than public+void, every time I write it another way. Sometimes "static public void" sometimes "public static void" etc.

这些关键字的最佳顺序(最佳实践)是什么?

What is the best order (best practices) for these keywords?

[abstract / static] [final] [synchronized] [public / private / protected] [result_type]

[abstract/static] [final] [synchronized] [public/private/protected] [result_type] ???

推荐答案

在理论上,如果你说public static final或final static public并不重要,但如果你遵循通常的惯例,其他人将能够更容易地阅读你的代码。以下是首选顺序:

In theory it does not matter if you say public static final or final static public, but if you follow the usual convention, other people will able to read your code more easily. Here is the preferred order:


[public |保护|私人]

[ public | protected | private ]

静态

抽象

[transient | volatile]

[ transient | volatile ]

final

native

int |长| String |类|枚举|界面等]

[ int | long | String | class | enum | interface etc. ]

这篇关于修饰符Java中的关键字顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆