Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it necessary to use @+id instead of @id?

Tags:

android

I know the difference between @+id and @id (see this accepted answer). However, I always get the feeling that I'm doing the job of the AAPT compiler when I write the '+' in @+id.

Is there a reason the resource compiler cannot infer by itself if an identifier must be created or just reused? An underlying hashtable structure would do the job: every resource with the same id go into the same bucket, and if the key does not exist, just create it.

like image 526
Aurelien Ribon Avatar asked Oct 23 '13 13:10

Aurelien Ribon


1 Answers

Probably the compiler would not be able to differentiate between a 'right' and a 'wrong' id. If it finds a new id (i.e. one that is not in the underlying hashtable), it would always assume it to be a right, new id. It would not be able to differentiate between an actual new id and a mistyped id.

like image 106
Piovezan Avatar answered Oct 16 '22 09:10

Piovezan