I need to change the value of a variable dynamically by passing it as a parameter by an auxiliary method. I always used the parameter values from right to left. You can change the variable from left to right:
Fields in my class:
private String ipAddress;
private String dnsAddress;
Set method to assign value to variable:
public void setDHCP(){
cmdAdress(ipAddress,"address", "dhcp");
cmdAdress(dnsAddress, "dnsservers", "dhcp");
}
Auxiliary method to make the set dynamic:
private void cmdAdress(String address, String type, String adresses){
//Isso não funciona
address = "netsh interface ip set ";
//Isso funciona mas não me é útil
//ipAddress = "netsh interface ip set ";
//restante do código
address += type;
address += " name = \"" + adapterName + "\" ";
address += adresses + " ";
}
The expected value would look something like this:
ipAddress: netsh interface ip set address name = \"OffBoard\" static 192.168.1.220 255.255.255.0 192.168.1.1
dnsAddress: netsh interface ip set dnsservers name=\"OffBoard\" static 192.168.1.1 primary no
Although there is no error, the value of the fields is always empty. Am I doing something wrong or demanding something that is not language?