- 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.
推薦閱讀
- LabVIEW Graphical Programming Cookbook
- Java Web基礎(chǔ)與實(shí)例教程(第2版·微課版)
- Learn Scala Programming
- PHP 編程從入門到實(shí)踐
- Asynchronous Android Programming(Second Edition)
- Lighttpd源碼分析
- 深入剖析Java虛擬機(jī):源碼剖析與實(shí)例詳解(基礎(chǔ)卷)
- Illustrator CC平面設(shè)計(jì)實(shí)戰(zhàn)從入門到精通(視頻自學(xué)全彩版)
- SQL Server 入門很輕松(微課超值版)
- Java EE架構(gòu)設(shè)計(jì)與開發(fā)實(shí)踐
- 基于GPU加速的計(jì)算機(jī)視覺編程:使用OpenCV和CUDA實(shí)時(shí)處理復(fù)雜圖像數(shù)據(jù)
- Scrapy網(wǎng)絡(luò)爬蟲實(shí)戰(zhàn)
- Python預(yù)測(cè)之美:數(shù)據(jù)分析與算法實(shí)戰(zhàn)(雙色)
- 高效使用Greenplum:入門、進(jìn)階與數(shù)據(jù)中臺(tái)
- 大話代碼架構(gòu):項(xiàng)目實(shí)戰(zhàn)版