Scenario/Problem
In the below code example, I implemented IMessage from java to kotlin Message. But when I pass a value to message variable it says val cannot be reassigned
val message = Message()
message.user = Author()
message.text = ""
messate.createdAt = Date()
message.id = ""
public interface IMessage {
String getId();
String getText();
IUser getUser();
Date getCreatedAt();
}
class Message : IMessage {
private var id: String = ""
private var createdAt = Date()
private var user = Author()
private var text: String = ""
override fun getId(): String {
return id
}
override fun getCreatedAt(): Date {
return createdAt
}
override fun getUser(): IUser {
return user
}
override fun getText(): String {
return text
}
}
Question
- What part of the code is wrong?
Expected Result
val message = Message()
message.id = ""
message.text = ""
message.user = Author()