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

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.

主站蜘蛛池模板: 翁牛特旗| 文昌市| 霸州市| 锡林浩特市| 黔西县| 石渠县| 湾仔区| 双江| 道孚县| 尉犁县| 墨竹工卡县| 白银市| 晋宁县| 阿坝县| 临澧县| 扶沟县| 虎林市| 和田县| 墨玉县| 北安市| 电白县| 台北市| 安义县| 上犹县| 樟树市| 花莲市| 莱西市| 乳山市| 华安县| 洪雅县| 乡城县| 曲松县| 阜新市| 栾川县| 江津市| 乳源| 青阳县| 天门市| 三河市| 尼勒克县| 满洲里市|