I have always thought that @+id
was only meant for ID definitions and not references. However, while using the visual constraint editor for ConstraintLayout, I found that all references to views for constraints are automatically set using that form instead of the usual @id
form.
From that, I became suspicious that maybe I was wrong. I knew the code would work if I used either form for references, so I went to the docs looking for the actual difference and turns out they say the same as I thought it was. The plus sign form is a sign for the compiler to add an ID to the R.id
class. That form being used in references only works because Android manages to deal correctly with duplicates, but everyone seems to agree that the best practice is to follow the docs and not have any duplicates. I even found a comment on an SO answer saying that "It works, but only because of the Android system being forgiving of duplicate IDs (...) However, this may change in the future, which will cause such layouts to become broken..." which is kind of terrifying.
The question then is why does AS itself use the other form, conflicting with their docs? Is it a bug? Is it reported somewhere? And if it is not a bug, then what is the actual importance of using one vs. the other? Is it actually confirmed that the theory of it potentially breaking all existing layouts is false?