How is the super signature function checked

1

The super() function is for calling the parent constructor and checking for proper signatures.

public class Pessoa {
    private String nome;
    private String endereco;
    private String telefone;
    private String cpf;
    private String telefoneCelular;

    public Pessoa(String nome, String endereco, String telefone) {
        this.nome = nome;
        this.endereco = endereco;
        this.telefone = telefone;
    }
}

public class Aluno extends Pessoa {

    public Aluno() {
        super();
    }

    public Aluno(String curso, double[] notas, String nome, String endereco, String telefone) {
        super(nome, endereco, telefone);
        this.curso = curso;
        this.notas = notas;
    }
}

Although I know it works this way, I do not understand how signing verification is done when the scope variables are different.

public class Aluno extends Pessoa {

    public Aluno() {
        super();
    }

    public Aluno(String curso, double[] notas, String teste1, String teste2, String teste3) {
        super(teste1, teste2, teste3);
        this.curso = curso;
        this.notas = notas;
    }
}

The check would be in the order in which the variables are declared within the super function, since all are of the same type ( String ).

  • test1 = name
  • test2 = address
  • test3 = phone
  • asked by anonymous 23.02.2017 / 02:28

    1 answer

    4

    Method Signatures only consider the quantity and types of parameters in their specific order, in addition, of course the name of the method, their names do not matter. So if you have two methods with the same name and both have three parameters of type String , it will give error, because the signature is the same even if the parameter names are other.

    You are responsible for using the method correctly, as already stated in the comments.

    If it is very important not to be confused, you have a technique that I do not think is good in most situations. If you use it just for this I do not recommend it.

    Create classes for each of these members, there you will have 3 different types. Something like this:

    public class Nome {
        private String nome;
        //e todo os resto aqui, construtor, métodos acessores, operações, validações, etc.
    }
    public class Endereco {
        private String endereco;
        //e todo os resto aqui, construtor, métodos acessores, operações, validações, etc.
    }
    public class Telefone {
        private String telefone;
        //e todo os resto aqui, construtor, métodos acessores, operações, validações, etc.
    }
    

    I've placed it on GitHub for future reference .

        
    23.02.2017 / 03:16