java - Android Annotation Working of @IdRes -
i using setid
method of view
class. according method
public void setid(@idres int id) // accept resource id
when tried use method hardcoded int
value(let 100), method start throwing correct warning expected-
actionbutton.setid(100);
expected resource of type id.
but when converted hardcoded value method , never defined method return @idres
, warning gets silent.
private int getviewid() { return 100; }
method call set id.
actionbutton.setid(getviewid());
isn't both same. hardcoded int
, int
return method. why in 1 case method throwing warning , in gets silent.
for sake tried stringres
getting warning in both cases.
private void setmystring(@stringres int resourcestring) {}
warning in both below cases-
setmystring(1); setmystring(getstringid()); getstringid returns int value
it lint warning since method expects variable r.id class.
regarding case of value returned method, lint doesn't bother check whole function whether returning hardcoded integer or actual id.
from documentation of @idres states:
denotes integer parameter, field or method return value expected id resource reference (e.g. android.r.id.copy).
also annotation exist in source code documentation. after code compiled, annotation removed.
Comments
Post a Comment