gpt4 book ai didi

java - Valhalla 的值对象可以保存泛型类型并在它们是原始类型时将其扁平化吗?

转载 作者:行者123 更新时间:2023-12-02 10:51:11 24 4
gpt4 key购买 nike

威尔JEP 169: Value ObjectsJEP 218: Generics over Primitive Types规范可以协同工作吗?

或者更好的是,以下情况可能吗?

@jvm.internal.value.ValueCapableClass
final class Tuple<T1, T2> {

private final T1 t1;
private final T2 t2;

// ...

}

然后

// t1 and t2 flattened because they are ints
final Tuple<int, int> tuple;
<小时/>

我问这个是因为我还没有看到使用泛型类型的 @ValueCapableClass 示例,仅 examples like this one :

@jvm.internal.value.ValueCapableClass
final class MyValue {
final int x, y;
// ...
}

我读自 JEP 218: Generics over Primitive Types (强调我的):

Generic type arguments are constrained to extend Object, meaning that they are not compatible with primitive instantiations unless boxing is used, undermining performance. With the possible addition of value types to Java (subject of a separate JEP), this restriction becomes even more burdensome. We propose to remedy this by supporting specialization of generic classes and interfaces when instantiated with primitive type arguments. We propose to remedy this by supporting specialization of generic classes and interfaces when instantiated with primitive type arguments.

With the eight primitive types being the only ones hostile to generics, this is tolerable but annoying; with the advent of value types, this restriction would be far more painful.

但我不清楚它们是否可以一起工作(218169 的扩展),或者通用的 @ValueCapableClasses 可以仅用于非泛型类。

最佳答案

根据this Brian Goetz's talk

[...] they [Value Types] can use generics, they can have type variables [...]

看来泛型正在未来的版本中得到支持。

关于java - Valhalla 的值对象可以保存泛型类型并在它们是原始类型时将其扁平化吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52169787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com