Java: $NON-NLS-1$

原创
2010/07/29 18:05
阅读数 1.2K

Look at this snap:

public static String valueOf(boolean value) {   
        return value ? "true" : "false"; //$NON-NLS-1$ //$NON-NLS-2$
}

What is "//$NON-NLS-1$ //$NON-NLS-2$" mean ?

It's used by Eclipse to indicate that a string doesn't need to be translated, probably because it's not going to be seen by the application's users. Netbeans uses NOI18N for the same purpose.

If you don't add that, you'll get a compiler warning. It doesn't stop your code from compiling into a valid class file, but it tells you that you may be doing something undesirable. You are free to ignore the warning. But if you don't want to see it at all--perhaps because too many warnings about something that you're doing on purpose clutters up the output and obscures warnings you do care--then you can add that $NON-NLS-1$ to tell the compiler not to produce the warning.

It's just about fine-tuning which warnings you do and do not care to see.

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
1 收藏
0
分享
返回顶部
顶部