简体   繁体   English

静态public boolean vs public静态布尔

[英]static public boolean vs public static boolean

What is the difference between using static public boolean and public static boolean for methods? 为方法使用static public booleanpublic static boolean什么区别?

I just tried both and both seem to compile fine and have the same effect unless I am doing it wrong. 我只是尝试了两者,除非我做错了,否则两者似乎都能很好地编译并且具有相同的效果。 Which one is better and why? 哪一个更好,为什么?

There's absolutely no difference, but putting public first is slightly preferred in terms of conventions. 绝对没有区别,但是就惯例而言,将public放在第一位比较可取。 From section 8.4.3 of the Java Language Specification : Java语言规范的8.4.3节开始

MethodModifier : one of MethodModifier :其中之一

 Annotation 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生产中显示的顺序一致。

I just tried both and both seem to compile fine and have the same effect unless I am doing it wrong. 我只是尝试了两者,除非我做错了,否则两者似乎都能很好地编译并且具有相同的效果。 Which one is better and why? 哪一个更好,为什么?

They are pretty same. 他们是一样的。 No difference only first case is less readable. 没有区别,只有第一种情况可读性差。 I think second case is more human-readable and you should program for humans so choose option that is more readable. 我认为第二种情况更易于理解,您应该为人类编程,因此选择更易理解的选项。 Also by conventions you should use first. 同样按照惯例,您应该先使用。

This is similar if you ask for null != obj or obj != null both are same but first case is sometimes used but is much less readable and for me it's annoying. 如果您要求null != objobj != null两者都相同,但是有时使用第一种情况,但可读性差得多,这对我来说很烦人。

public static boolean is more readable than static public boolean public static booleanstatic public boolean更易读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM