eclipse build path與java Compiler

來源:互聯網
上載者:User

標籤:

在eclipse中開發的項目有個java build path中可以配置的jdk,還有個java compiler中可以配置compiler level,這兩個是有區別的,java compiler level的JDK版本是你在eclipse中開發代碼,給你提示報錯的和將java檔案編譯成class檔案需要用到的版本;build path中版本號碼的作用是指明你將來啟動並執行環境。

如果build path的版本低於compiler版本,則會報 Unsupported major.minor version 51.0(高版本的版本號碼,以jdk7為例)。

網上大部分文章說java compiler level和build path的作用與本人的不同。在他們的說明下,我在eclipse嘗試過將compiler level設定成1.6,build path 設定成1.7,編寫以下程式:

public class Test {    public static void main(String[] args) {        // TODO Auto-generated method stub        long test = 1234_5678_9012_3456L;  //jdk7新文法        System.out.println(test);    }}

結果程式無法編譯成功,eclipse提示錯誤,強制運行報以下錯誤

Exception in thread "main" java.lang.Error: Unresolved compilation problem:     Underscores can only be used with source level 1.7 or greater    at Test.main(Test.java:6)

即使將系統的java home設定成jdk7,用java命令跑也是報上述錯誤。

 

如果將compiler level設定成1.7,build path 設定成1.6,則eclipse不會報編寫錯誤,但是run後,則會報Unsupported major.minor version 51.0錯誤。

 

eclipse build path與java Compiler

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.