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

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.

主站蜘蛛池模板: 郁南县| 平陆县| 宁河县| 浠水县| 海宁市| 西藏| 布拖县| 宜川县| 若羌县| 澄迈县| 永丰县| 南靖县| 巴彦县| 尼勒克县| 宜兰县| 曲松县| 象山县| 兴海县| 大名县| 共和县| 绍兴县| 九龙坡区| 寿宁县| 晋中市| 新建县| 达州市| 武功县| 广宗县| 信阳市| 息烽县| 甘肃省| 外汇| 湖南省| 林口县| 潮州市| 德令哈市| 湖口县| 郓城县| 大悟县| 邹城市| 云霄县|