Meaning of $ NON-NLS-1 $ annotation in eclipse

Source: Internet
Author: User
Tags first string

When I was just getting started with Eclipse, I often see some strange comments in the official example, for example: shell. settext (messages. getstring ("testref. Hello"); // $ NON-NLS-1 $
What exactly does this $ NON-NLS-1 $ represent? This problem was ignored after a while. Today, when reading rich client tutorial part 2, I accidentally discovered the true meaning of this line of comment ......
^_^ Is an unexpected result.

This is actually a method that supports i18n in eclipse. The standard structure of eclipse defines all string constants. properties, such as testref. hello is actually. A key testref in properties. hello = Hello

Now you may be able to guess the meaning of comments $ NON-NLS-1 $. I personally guess it may be the abbreviation of non-need localize string 1. In the RCP document, the string is described as follows:$NON-NLS-1$Is a hint for both the compiler and the externalization wizard that the first character string on this line is a tag or Keyword of some sort and shoshould not be localized. that is, $ NON-NLS-1 $ indicates that the first string variable in the row is a tag or keyword and does not need to be localized

Testref. Java


Public class testref {
Public static void main (string [] ARGs ){
Shell shell = new shell ();
Shell. settext (messages. getstring ("testref. Hello"); // $ NON-NLS-1 $
}

Messages. Java


Public class messages {
Private Static final string bundle_name = "test"; // $ NON-NLS-1 $
Private Static final resourcebundle resource_bundle = resourcebundle. getbundle (bundle_name );
Private Messages (){
}
Public static string getstring (string key ){
Try {
Return resource_bundle.getstring (key );
} Catch (missingresourceexception e ){
Return '! '+ Key + '! ';
}
}
}

Test. Properties


Testref. Hello = Hello

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.