- Java 11 and 12:New Features
- Mala Gupta
- 105字
- 2021-07-02 12:26:58
Compulsory non-null initialization
A local variable defined with var must be initialized with its declaration, or the code won't compile. The compiler can't infer the type of an uninitialized variable or a variable that is assigned a null value. The following code won't compile:
var minAge; // uninitialized variable var age = null; // variable assigned a null value
The following image illustrates what would happen if the uninitialized variable age went to seek entrance to the Mr. Java compiler place. The compiler won't let age in:

Variable definition using var must always be accompanied by its initialization, or the code will fail to compile.
推薦閱讀
- C#完全自學(xué)教程
- 劍指Offer(專項突破版):數(shù)據(jù)結(jié)構(gòu)與算法名企面試題精講
- Selenium Design Patterns and Best Practices
- Java從入門到精通(第4版)
- Servlet/JSP深入詳解
- 精通軟件性能測試與LoadRunner實戰(zhàn)(第2版)
- 精通Scrapy網(wǎng)絡(luò)爬蟲
- MySQL數(shù)據(jù)庫管理與開發(fā)實踐教程 (清華電腦學(xué)堂)
- Mastering Rust
- 零基礎(chǔ)入門學(xué)習(xí)Python
- Drupal 8 Module Development
- Mastering Xamarin.Forms(Second Edition)
- Linux Shell核心編程指南
- 深度學(xué)習(xí)入門:基于Python的理論與實現(xiàn)
- Visual Basic 程序設(shè)計實踐教程