Reputation: 674
I have an entity class for an app I'm building in Java that looks like this:
@Entity(tableName = "entry_table")
public class Entry {
@PrimaryKey(autoGenerate = true)
private int id;
private String username, hint, password;
public Entry(String username, String hint, String password){
this.username = username;
this.hint = hint;
this.password = password;
}
public Entry(){}
public int getId() {return id;}
public void setId(int id) {this.id = id;}
public String getUsername() {return username;}
public void setUsername(String username) {this.username = username;}
public String getHint() {return hint;}
public void setHint(String hint) {this.hint = hint;}
public String getPassword() {return password;}
public void setPassword(String password) {this.password = password;}
}
I'm trying to do the same thing in Kotlin. I thought about converting the file to Kotlin but I want to get my hands used to writing Kotlin code. Some of the implementations that I found online were quick to throw errors.
This is what I have so far:
@Entity(tableName = "entry_table")
data class Entry()
Upvotes: 2
Views: 423
Reputation: 20714
Your entity in Kotlin would look like this:
@Entity(tableName = "entry_table")
data class Entry(@PrimaryKey(autoGenerate = true) val id: Int,
val username: String,
val hint: String,
val password: String)
Upvotes: 2