I have a class which implements Handler.Callback
So, in my code i开发者_Go百科 have something like this :
@Override
public boolean handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what)
{
case ThreadMessages.MSG_1:
{
break;
}
case ThreadMessages.MSG_2:
{
break;
}
case ThreadMessages.MSG_3:
{
break;
}
case ThreadMessages.MSG_4:
{
break;
}
case ThreadMessages.MSG_5:
{
break;
}
}
return false;
}
How should i comment this method to reflect the messages that my class can handle ?
The purpose here , is to let a developer know what message he can send to the class without having to read the source code , just using the java doc.
Thanks
My Advice:
In class ThreadMessages
Rename MSG_1
and the other static fields to some meaningful names.
Above your handleMessage
Add the following comments:
/**
* Can handle {@link ThreadMessages#MSG_1}, {@link ThreadMessages#MSG_2}, {@link ThreadMessages#MSG_3}, {@link ThreadMessages#MSG_4}, and {@link ThreadMessages#MSG_5}
*/
And in class ThreadMessages
Explain each static feild by adding above it
/**
* this is used for
*/
Oracle has a great document about how to comment your code so you can generate Java Docs later on.
精彩评论