Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试通过注入添加模型以查看
val model = PersonModel by inject()
但错误:
“PersonModel”没有伴随对象。
我究竟做错了什么 ?
你需要使用:,而不是=。
:
=
val model: PersonModel by inject()
错误的原因是,当编译器看到 时val model = PersonModel,它假定您正在尝试将PersonModel类的伴随对象分配给model,但没有,因此它会为您提供最有用的消息,而不会意识到您犯了一个简单的语法错误。
val model = PersonModel
PersonModel
model