I have different classes called English
, Spanish
, French
, etc.:
Class English{
String name = "English";
String alias = "ENG";
}
Class French{
String name = "French";
String alias = "Fre";
}
Similarly other language classes.
And one more class called Language
:
Class Language{
String name = "";
String alias = "";
}
Depending upon my requirements I want to cast English/French/Spanish to my Language class.
Class ABC{
main(){
Language lan = new Language();
Object obj = getObject(1);
if(obj instanceof English){
lan.name = ((English)obj).name;
lan.aliasName = ((English)obj).aliasName;
}
}
}
If I have 10 languages, do I need to write the same code for 10 different languages? In this case, how can I make a single method and pass those arguments as parameters? Something like this:
setVariablesForLanguage(String className, Object obj)
Here i showed only 2 variables but my class will contain more than 100 variables.. My actual rewquirment is I want to set the my Language variables From one of those languages..