When working with Javascript, I have the ability to define static variables like this:
var Services = {
Pandora : {name: "ziggy", password: "stardust"},
AppleMusic : {name: "steve", password: "jobs"},
SoundCloud : {name: "bedroom", password: "studio"}
};
I can then easily access the data members using object notation.
console.log(Services.Pandora.name);
console.log(Services.AppleMusic.name);
console.log(Services.SoundCloud.password);
However, when trying to achieve the same in Java, I find it challenging. The solutions discussed, such as nested classes or ArrayLists, seem overly complex and verbose. Is there a simpler way to accomplish this in Java? Any insights would be appreciated!
Later....
After some experimentation, I opted to use an enum to declare static variables in Java:
public enum Service {
Batanga ("Batanga","Batanga","my_name","my_password",""),
Calm ("Calm Radio","Calm Radio","my_name","my_password",""),
;
private final String svcName;
private final String svcFullName;
private final String login;
private final String pass;
private final String url;
Service(String svcName, String svcFullName, String login, String pass, String url) {
this.svcName = svcName;
this.svcFullName = svcFullName;
this.login = login;
this.pass = pass;
this.url = url;
}
public String getSvcName() {
return svcName;
}
public String getSvcFullName() {
return svcFullName;
}
public String getLogin() {
return login;
}
public String getPass(){
return pass;
}
public String getUrl() { return url; }
}
Thank you for your help!