Follow part one:
class Pessoa{
String firstName
String lastName
int age
def address
static main(args) {
def p = new Pessoa()
p.setFirstName("Lars")
p.lastName = "Vogel"
p.address = "Homestreet 3"
println(p.firstName + " " + p.lastName);
println ""
p = new Pessoa(firstName: "Peter", lastName:"Mueller");
println(p.firstName + " " + p.lastName);
println ""
p = new Pessoa(firstName: "Aline", lastName: "Gonzaga")
println (p.firstName+" "+ p.lastName)
}
Follow part two:
class Pessoa{
String firstName
String lastName
int age
def address
static main(args) {
def p = new Pessoa()
p.setFirstName("Lars")
p.lastName = "Vogel"
p.address = "Homestreet 3"
println(p.firstName + " " + p.lastName);
println ""
def p1 = new Pessoa(firstName: "Peter", lastName:"Mueller");
println(p1.firstName + " " + p1.lastName);
println ""
def p2 = new Pessoa(firstName: "Aline", lastName: "Gonzaga")
println (p2.firstName+" "+ p2.lastName)
}
My question would be in p1
and p2
of the second example. Why are there two ways of instantiating? What is the best option to do this? Explain to me why the first form is that way and the second is the other way. Does it have to do with performance?