gpt4 book ai didi

scala - 在 Scala 中访问类型成员

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

我有一个类型为成员的玩具类 T .

class A { type T = Int }

如何访问我的类型成员。例如获取类型或修改它。
val a = new A
a.T = String //error: value T is not a member of A

T是我的成员(member),为什么我不能访问它?

最佳答案

类型成员比普通的类成员更像是泛型参数。与泛型参数一样,您不能重新分配类型参数或从类的实例访问它。阅读更多关于类型成员的信息 here ,以及抽象类型和泛型参数的区别here .

关于scala - 在 Scala 中访问类型成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29269940/

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