官术网_书友最值得收藏!

What is type inference?

Imagine solving a riddle, such as the one shown in the following image, with multiple constraints in the form of hints. You resolve the constraints to derive the answer. You can compare type inference to generating constraints and then resolving them, in order to determine the data types in a programming language. Type inference is the capability of the compiler to determine the type of the data, by using the information that is already available in the code—literal values, method invocations, and their declarations. For a developer, type inference reduces verbosity, as indicated by the following diagram:

For your reference, the answer to the preceding riddle is 87 (just turn the image upside down, and you'll find the numbers in a sequence).

Type inference is not new to Java. It has been taken to the next level with the introduction of var (with local variables) in Java 10.

Let's dive into the topic by looking at some examples of var.

主站蜘蛛池模板: 山西省| 原平市| 突泉县| 溧水县| 漳浦县| 阳朔县| 盐城市| 五华县| 蒲城县| 高阳县| 米泉市| 体育| 张家界市| 钟山县| 京山县| 武邑县| 丁青县| 光泽县| 临海市| 博客| 汤原县| 武胜县| 达州市| 博湖县| 南澳县| 莒南县| 佛学| 昂仁县| 萍乡市| 比如县| 昂仁县| 项城市| 久治县| 定结县| 沾益县| 阜城县| 鄂托克旗| 股票| 石嘴山市| 突泉县| 大化|