List of reserved words in Android

帅比萌擦擦* 提交于 2019-12-05 03:43:10
CommonsWare

To my knowledge there are a set of rules you need to know:

No uppercase is allowed.

AFAIK, that is not a rule. A convention is to use all lowercase, but mixed case has worked.

NOTE: In layouts you can ONLY use lowercase letters (a-z), numbers (0-9) and underscore (_).

No symbols apart from underscore

Correct. More accurately, the name has to be a valid Java data member name, which limits you to letters, numbers, and underscores, and it cannot start with a number.

No numbers

That is not a rule, though your name cannot start with a number, as noted above.

Appart from those (please correct me if I'm wrong) I think you can't use any of the reserver words from JAVA which after a little googling appear to be the following:

That is because reserved words are not valid Java data member names.

So my question would be if there is somewhere in the docs that I've failed to locate, that explains in detail what we can and can not use for resource names

Apparently not.

Well my answer would be a mix of some pages where you can find what you need.

1.- First i would recommend you to read the Conventions that Oracle recommends for java

NOTE: especially the section of "Naming Conventions" (this is something that most of the other answers have), after that i would suggest you to read the "Java Languages Keywords" cause you can not use any of those words, BUT remember that JAVA is CASE-SENSITIVE, so if you write "Abstract" instead of "abstract" then is OK, but of course that may confuse someone later one (maybe yourself).

2.- Last but not least you can read the "Code Style Guidelines", this are the conventions that contributors to the android source code need to apply to their code to be accepted.

If you follow this rules, your code not only will be valid (Of course this is important), is going to be more readable for you and others, and if another person needs to make some modification later on, that would be a easier task than if you just start typing random names like "x1, x2, X1, _x1, etc..."

OTHER USEFUL ARTICLE:

If you are starting your app, then this article is going to be very useful for you, it explains why the use of setters and getters in a exaggerated way is a very bad practice, they need to be ONLY if is needed not just for setting and getting every variable in your object.

Tassos Bassoukos

If you use identifiers that are valid Java variable names (this means consist only of a-z, A-Z, 0-9 and the underscore characters) you will not have any problems. The actual namespace is probably larger, but this works for me.

documentation

I'll just chip in and say this:

You can't use keywords but managing android resources isn't quite easy either... for instance, you cannot have different folders for drawables, they need to go to drawable-xxxx folder...

So, try to come up with sensible prefixes for your drawables and selectors.

Android accepts all valid Java variable names so I don't really see where this question comes from.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!