Use the package mechanism in Java to implement Conditional compilation

Source: Internet
Author: User

Javamso-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-font-family:
Calibri; MSO-Hansi-theme-Font: minor-Latin "> NO cmso-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-font-family:
Calibri; MSO-Hansi-theme-Font: minor-Latin "> the" Conditional compilation "feature in the language. This feature applies to cmso-ascii-theme-Font: minor-Latin; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: calibri; MSO-Hansi-theme-Font: minor-Latin "> the language is used to solve cross-platform code problems, you can compile different parts of the code based on the specific platform on which the Code runs. Because javamso-ascii-theme-Font: minor-Latin; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: calibri; MSO-Hansi-theme-Font: minor-Latin "> is designed as a cross-platform language, therefore, this feature is unnecessary.

MSO-ascii-font-family: calibri; MSO-ascii-theme-Font: minor-Latin; MSO-Fareast-font-family:
; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-font-family: calibri;
MSO-Hansi-theme-Font: minor-Latin "> however, Conditional compilation is useful for code debugging. Like in cmso-ascii-theme-Font: minor-Latin; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: calibri; MSO-Hansi-theme-Font: minor-Latin "> languages are the same, some Conditional compilation switches allow some debugging code to be used only during the development process, but not in the released version.

MSO-ascii-font-family: calibri; MSO-ascii-theme-Font: minor-Latin; MSO-Fareast-font-family:
; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-font-family: calibri;
MSO-Hansi-theme-Font: minor-Latin "> we can use javamso-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-font-family:
Calibri; MSO-Hansi-theme-Font: minor-Latin "> packagemso-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-font-family:
Calibri; MSO-Hansi-theme-Font: minor-Latin "> to simulate the concept of Conditional compilation, it can be used for javamso-ascii-theme-Font: minor-Latin; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: calibri; MSO-Hansi-theme-Font: minor-Latin "> code debugging and development.

MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-font-family:
Calibri; MSO-Hansi-theme-Font: minor-Latin "> the code is as follows:

Code Package com. Vista. Debug

Public class assert
{
Private Static void printerr (string MSG)
{
System. Err. println (MSG );
}
Public final static void istrue (Boolean exp)
{
If (! Exp) printerr ("assertion failed ");
}
Public final static void isfalse (Boolean exp)
{
If (exp) printerr ("assertion failed ");
}
Public final static void istrue (Boolean exp, string MSG)
{
If (! Exp) printerr ("assertion failed" + MSG );
}
Public final static void isfalse (Boolean exp, string MSG)
{
If (! Exp) printerr ("assertion failed" + MSG );
}
}

 

MSO-ascii-font-family: verdana; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: verdana "> to use this asserted class for debugging in our code, you only need to introduce the following package:

Import com. Vista. Debug .*;

 

MSO-ascii-font-family: verdana; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: verdana "> when preparing to compile the release version, we need to clear the previously introduced asserted mechanism, for this reason, we only need to create a different package; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-font-family: verdana "> Create a class named assert; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-font-family: verdana"> with the Code as follows:

Code Package com. Vista. Release

Public class assert
{
Private Static void printerr (string MSG ){}
Public final static void istrue (Boolean exp ){}
Public final static void isfalse (Boolean exp ){}
Public final static void istrue (Boolean exp, string MSG ){}
Public final static void isfalse (Boolean exp, string MSG ){}
}

 

MSO-ascii-font-family: verdana; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: verdana "> Import; MSO-ascii-font-family: verdana; MSO-Fareast-font-family: MSO; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: verdana "> the statement is modified as follows:

Import com. Vista. Release .*;

 

In this way, the asserted mechanism is removed from our code.

 

 

 

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.