Thought of by SWT. getplatform ()

Source: Internet
Author: User
Tags gtk

 

In eclipse3.4, The SWT class provides the getplatform method to return to the operating system platform.

At first, I thought this method must have been obtained by calling the functions of the system platform or the native method.

With this idea. View the source code of SWT.

 

System. Out. println (SWT. getplatform (); // return to the system platform

Source code:

/**

* Returns the SWT platform name.

* Examples: "Win32", "motif", "GTK", "photon", "Carbon"

*

* @ Return the SWT platform name

*/

Public static string getplatform (){

Return platform. Platform;

}

 

Package org. Eclipse. SWT. Internal;

 

Public class platform {

 

Public static final string platform = "Win32 ";

 

}

 

The source code shows that it is not a system platform function or local method called. However, when the strings represented by the current platform are hard-coded (written to the dead ),

 

In the final state variable of platform. platform. The source code above is viewed in the wndows 32bit version.

 

At the same time, under Linux (Linux 32bit), I checked the Linux version of Eclipse.

It is found that the getplatform method in the SWT class is also hard-coded, as follows:

Public static string getplatform (){

Return "GTK ";

}

 

 

 

Users who often download and update eclipse know that eclipse officially provides three different versions of Eclipse, windows, Linux, and Mac, for users to download.

View the source code above. We can know that eclipse on different platforms has different jar libraries corresponding to SWT.

 

That is, to provide multiple platform versions (such as Windows and Linux) during RCP development, you must provide one, A Linux version is also provided (you need to use eclipse of Linux for packaging ).

At the same time, it should be clear that cross-platform is only a relative concept.

 

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.