- Java 11 and 12:New Features
- Mala Gupta
- 151字
- 2021-07-02 12:27:00
Reassigning values to inferred variables
As is applicable to all non-final variables, you can reassign value to inferred variables. Just ensure that the reassigned value matches its inferred type. In the following code, since the type of the age variable is inferred as int, you can't assign a decimal value of 10.9 to it. Similarly, since the type of the query variable is inferred as StringBuilder. The type of a variable is inferred just once, as follows:
var age = 9; // type of variable age inferred as int age = 10.9; // can't assign 10.9 to variable of type int var query = new StringBuilder("SELECT"); // Type of variable
// query is StringBuilder query = query.toString() + "FROM" + "TABLE"; // won't compile; // can't assign String
// to variable query
The type of a local variable defined using var is inferred only once.
推薦閱讀
- Angular UI Development with PrimeNG
- Android 9 Development Cookbook(Third Edition)
- 精通API架構(gòu):設(shè)計、運維與演進
- 程序是怎樣跑起來的(第3版)
- Jenkins Continuous Integration Cookbook(Second Edition)
- 零基礎(chǔ)趣學(xué)C語言
- INSTANT Adobe Edge Inspect Starter
- Spring Boot+Vue全棧開發(fā)實戰(zhàn)
- Modern C++ Programming Cookbook
- PrimeFaces Blueprints
- 計算機應(yīng)用技能實訓(xùn)教程
- Anaconda數(shù)據(jù)科學(xué)實戰(zhàn)
- Java自然語言處理(原書第2版)
- Learning Cocos2d-JS Game Development
- 軟件測試技術(shù)