我收到此代码的死代码警告:
Topic topic = findTopicByID(point.getIDTopic());
if (topic != null)
{
...
}
else if (topic == null)
{
// I get Dead code warning for every thing I write here!
}
有时当我收到警告但一切正常时,我重新启动 IDE 并且不再收到该警告!但这一次……
编辑:
public Topic findTopicByID(int IDTopic) {
for (Topic topic : topics)
if (topic.getID() == IDTopic)
return topic;
return null;
}
编辑:这里的完整代码:
Topic topic = Res.getSchedule().getTopicBox().findTopicByID(point.getIDTopic());
Section section = topic.findSectionByID(point.getIDSection());
if (topic != null)
{
View rowView = inflater.inflate(R.layout.daily_day_day_row, lLDoneWorks, false);
TextView tVLabel = (TextView) rowView.findViewById(R.id.daily_day_day_row_label);
TextView tVNum = (TextView) rowView.findViewById(R.id.daily_day_day_row_num);
TextView tVTopic = (TextView) rowView.findViewById(R.id.daily_day_day_row_topic);
TextView tVSection = (TextView) rowView.findViewById(R.id.daily_day_day_row_section);
int color = topic.getColor();
tVLabel.setBackgroundColor(color);
tVNum.setTextColor(color);
tVTopic.setTextColor(color);
tVSection.setTextColor(color);
tVLabel.setText(topic.getName().substring(0,1).toUpperCase(Locale.US));
tVNum.setText(Integer.toString(point.getCount()));
tVTopic.setText(topic.getName());
if (point.getIDSection() != Point.DEFAULT_SECTION)
tVSection.setText(section.getName());
lLDoneWorks.addView(rowView);
}
else if (topic == null)
{
TopicArchived archivedTopic = Res.getSchedule().getTopicBox()
.findArchivedTopicByID(point.getIDTopic());
if (archivedTopic == null)
removedTopicsPoint += point.getCount();
else
archivedTopicsPoint += point.getCount();
}