Hi there,
I am completely new to scala. I am fascinated by the concept of case classes. To my understanding, it allows me to write POJOs in a single line. I could basically rewrite the following Java code:
class Person
{
private String firstname;
private String lastname;
private String email;
public Person(String firstname, String lastname, String email)
{
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
}
// getters and setters
}
into something beautiful:
case class Person(val firstname: String, val lastname: String, val email: String);
However, let’s assume another constructor that automatically sets the value of email:
public Person(String firstname, String lastname)
{
this(firstname, lastname, String.format("%s@%s.com", firstname, lastname);
}
What is the scala way of extending the case class by the given constructor. I know that I could just stick to Java code in scala but I don’t want to violate the beauty of scala
Any ideas how to solve that?
thanks, Simon