嗨,我有 20 个字符串,除了类名之外,每个字符串都有相同的包结构。这些字符串需要根据需要传递给方法。参考下面的代码:
public static final String RECENT_MSG_ = "com.foo.xxs.RecentMessage";
public static final String PROJ_ = "com.foo.xxs.Proj";
public static final String FORECAST = "com.foo.xxs.Forecase";
public static final String REQUEST = "com.foo.xxs.Request";
public static final String UNAPPROVED = "com.foo.xxs.UnApproved";
public static final String UNPOSTED = "com.foo.xxs.Unposeted";
public static final String VACANT = "com.foo.xxs.Vacant";
public static final String ORG_VIOL = "com.foo.xxs.OrgViolation";
public static final String ORG_WARN = "com.foo.xxs.OrgWarning";
public static final String EMP_VIOL = "com.foo.xxs.EmpViolation";
public static final String EMP_WARN = "com.foo.xxs.EmpWarning";
public static final String TS_WARN = "com.foo.xxs.TSWarn";
public static final String TS_VIOL = "com.foo.xxs.TSViolation";
public static final String AGE_GROUP = "com.foo.xxs.AgeGroup";
private void rescheduleTasks(long _taskType,String value)
{
if(_taskType == 1000 &&(_sSchedTaskMgr.getInstance().getCurrentScheduledTaskInfo(RECENT_MSG_)==null))
{
// do something
}
}
这也可以按如下方式完成:
public static final String RECENT_MSG_ = "RecentMessage";
public static final String PACK ="com.foo.xxs."
并像这样连接字符串:
if(_taskType == 1000 &&(_sSchedTaskMgr.getInstance().getCurrentScheduledTaskInfo(PACK+RECENT_MSG_)==null))
哪一个会更好?