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

Non-denotable types

Java types that you can use in a program, like int, Byte, Comparable, or String, are called denotable types. The types used by a compiler internally, like the subclass of an anonymous class, which you can't write in your program, are called non-denotable types.

Up until now, type inference with variables seemed quite easy to implement—just get the information about the values passed to a method and returned from a method, and infer the type. However, it isn't as simple as that when it comes to inference with non-denotable types—null types, intersection types, anonymous class types, and capture types.

For example, consider the following code and think about the type of the inferred variables:

// inferred type java.util.ImmutableCollections$ListN 
var a = List.of(1, "2", new StringBuilder());
var b = List.of(new ArrayList<String>(), LocalTime.now());

Type of variable a and b isn't a type that you would have read before. But that doesn't stop them from being inferred. The compiler infers them to a non-denotable type.

主站蜘蛛池模板: 贵南县| 红原县| 渭源县| 盘山县| 江阴市| 长宁区| 辽宁省| 云南省| 雅江县| 闵行区| 新龙县| 徐水县| 万山特区| 原平市| 台山市| 新乐市| 正阳县| 鹿泉市| 陈巴尔虎旗| 襄汾县| 康定县| 林甸县| 巴中市| 塔河县| 玉田县| 金平| 安泽县| 潞城市| 砀山县| 徐汇区| 南通市| 寿宁县| 清流县| 周口市| 铁岭县| 手游| 罗定市| 万源市| 阳西县| 唐河县| 梅河口市|