Reputation: 769
I have this class here:
@Document
open class Product(){
@Indexed(unique = true)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
var productKey: KeyClass = KeyClass(UUID.randomUUID())
private set
}
In another class I want to write a function that sets a Product with a key like so:
myKey.forEach {item -> updateKey(Product(productKey = item.value)}
How can I write that logic in a correct syntax?
Upvotes: 0
Views: 135
Reputation: 7521
Problem is that productKey
is not a constructor parameter, that's why it can't be resolved by compiler for constructor invocation. You have 2 solutions.
productKey
inside constructor blockopen class Product(var productKey: : KeyClass) {
// other stuff
}
then Product(productKey = item.value)
will work as expected
Product
fromProduct(productKey = item.value)
to
Product().apply { productKey = item.value }
PS: private set
is useless in both cases. If you don't want productKey
to be changed then just make it val
not var
.
Upvotes: 2