强制开发人员在 DialogFragment show 方法中放置一个非空标记?

Forcing the developer to place a non-empty tag in the DialogFragment show method?

我想强制在 DialogFragment:

的显示方法中使用标签
MyDialogFragment fragment = MyDialogFragment.newInstance(args);
fragment.show(getSupportFragmentManager(), MANDATORY_TAG);

如果 MANDATORY_TAG""null,有没有办法强制执行此操作,或者以某种方式从片段中抛出错误?

if (tag == null || tag.isEmpty()) {
            throw new NullPointerException("Please add the Tag. Tag cannot be null or empty");
        }

编辑:

try {
    MyDialogFragment fragment = MyDialogFragment.newInstance(args);
    fragment.show(getSupportFragmentManager(), MANDATORY_TAG);
} catch (NullPointerException e) {
    e.printStackTrace();
}