- 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.
推薦閱讀
- Cocos2D-X權(quán)威指南(第2版)
- 算法訓(xùn)練營:入門篇(全彩版)
- Android Development with Kotlin
- OpenCV 3和Qt5計算機(jī)視覺應(yīng)用開發(fā)
- Java開發(fā)入行真功夫
- Internet of Things with the Arduino Yún
- 人人都懂設(shè)計模式:從生活中領(lǐng)悟設(shè)計模式(Python實現(xiàn))
- C#程序設(shè)計基礎(chǔ):教程、實驗、習(xí)題
- 組態(tài)軟件技術(shù)與應(yīng)用
- Nginx Lua開發(fā)實戰(zhàn)
- Java程序設(shè)計教程
- 大學(xué)計算機(jī)應(yīng)用基礎(chǔ)(Windows 7+Office 2010)(IC3)
- Less Web Development Cookbook
- Learning Redux
- Java EE框架開發(fā)技術(shù)與案例教程