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

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.

主站蜘蛛池模板: 比如县| 孟连| 林芝县| 郴州市| 沙洋县| 晋江市| 阳新县| 阜城县| 容城县| 高唐县| 共和县| 襄城县| 沅江市| 武清区| 北京市| 邯郸县| 凯里市| 铜川市| 鄂托克前旗| 石屏县| 夏河县| 文山县| 陇川县| 清镇市| 镇江市| 石家庄市| 揭阳市| 武城县| 盐池县| 分宜县| 宣化县| 三门峡市| 科技| 庆云县| 黄冈市| 汉中市| 集安市| 休宁县| 潞西市| 柳江县| 苍溪县|