简体   繁体   中英

How to update a variable with different string values in the same method using java?

Could some one please advise with the below?

private String dataName;
private String sourceType;

public void getConnectionData(){
    DataCollector data = new DataCollector();
    portNumber = data.getConnectionData(sourceType, dataName);
    channel  = data.getConnectionData(sourceType, dataName);
    hostName = data.getConnectionData(sourceType, dataName);    
    queueName = data.getConnectionData(sourceType, dataName);
    queueManager = data.getConnectionData(sourceType, dataName);

}

I have the above method, I am trying to make dataName equal the below for each of the above when I am trying to use the method from the other class.

    dataName = "portNumber";    
    dataName = "channel";   
    dataName = "hostName";  
    dataName = "queueName"; 
    dataName = "queueManager";

Could someone please advise how i go about it?

Thanks

Why not the usual:

portNumber = data.getConnectionData(sourceType, "portNumber");
channel  = data.getConnectionData(sourceType, "channel");
hostName = data.getConnectionData(sourceType, "hostName");    
queueName = data.getConnectionData(sourceType, "queueName");
queueManager = data.getConnectionData(sourceType, "queueManager");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM