Java: the reference to static context is similar to class self reference ‘this’, which is often used as the coding style

As mentioned in Python, I have been using class self - reference since the recent beginning of Java, whether it is mandatory or not I believe it helps the readability of the code because people who read it don't have to figure out the scope of variables themselves I want to work like a static scope: add a static keyword before all references to the static context, so the code is more self-evident But Java doesn't like it I know I can technically simply use class names, but it looks very ugly, especially when a class has a long name I can also prefix the names of static methods and properties with a special prefix, but I don't want to be seen as paranoid Do you think this is a good OOP style? Or should I completely forget anything and let javac do all the scope binding?

Solution

Some conventions use all usage of member fields (or even methods) as prefixes There are also conventions for prefixing variable or class names (notorious Hungarian symbols) For example, the official Android code style guide requires private member field names plus m - (for example, private int Msize) and private static plus s -

Personally, I hate these two conventions because they are just a mess of already very detailed java code Modern ide provides some means of visual differentiation For example, in eclipse, local variables are in standard black font and fields are in blue Static methods or fields are displayed in italics

They also provide a good way to browse the source code CTRL clicking on the name of a variable / method / type causes you to declare it correctly I have some suggestions As long as you hover over eclipse, eclipse even displays a tooltip containing information about this information

Yes, some people may think that you sometimes don't read code in the IDE, but in a simple text editor I sometimes do this to get a quick look at the code, but to be honest, when I want to do some serious coding, it's just a masochism not to use the IDE

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>