paulgreg paulgreg - 1 month ago 22
Java Question

What does $NON-NLS-1$ mean?

In Eclipse source code, I've found some '$NON-NLS-1$' in comments used like that :

private String toolTip = ""; //$NON-NLS-1$


What does that mean ?

Answer

They silence a warning that Eclipse emits when it encounters string literals (and has been configured to complain).

The idea is that UI messages should not be embedded as string literals, but rather sourced from a resource file (so that they can be translated, proofed, etc). Consequently, Eclipse can be configured to detect string literals, so that you don't accidentally have leave unexternalized UI strings in the code; however, there are strings which should not be externalized (such as regexps) and so, //$NON-NLS-1$ gives you a way to communicate that fact to the compiler.

Comments