How to detect the version of the compiler that is compiling my java source file -


hi writing java class enables of functionalities when compiled java7 upwards. know how find major/minor magic number compiled class file. need find way detect when compiler compiling source code. simple snippet this: ```

public class hey {     public static final boolean java_ver = ???; // how this??     public static foo() {         if (java_ver >= java7) {             // use fancy way introduced in java7         } else {             // go slow way of java6         }     } } 

```

code not executed during compilation. during compilation checked syntactical errors , converted byte code inside .class file. code lines can executed when run , hence thing can find out in code java runtime version. java runtime can found using java.version system property. here code that:

    string version = system.getproperty("java.version"); 

if want check java compiler version, perhaps use script compile code. maybe can have 2 different versions of file, each 1 apt 1 particular java version. in script check available java version , compile desired version of file. may want use single output common output directory.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -