I'm new to Java and I hope Java experts will not vote down my question just because it may seem rather primitive to them. So, this is something I want to achive in semi-pseudo code:
class Big {
? magic_field;
? magic_method (int _idx){
if (_idx == 1){
magic_field = new Object_1();
}
else if (_idx == 2){
magic_field = new Object_2();
}
...
else if (_idx == N){
magic_field = new Object_N();
}
return magic_field;
}
}
I've already tried to ask this question, but in the context of a real world class, real fields and procedures, but did not get an answer to my question. Practically all answers reused the idea of generics and started with something like
class Big <T extends Something>
But I want stress it heavily thousands of times - Object_1, Object_2, ..., Object_N may be drastically different classes that do not relate to each other - they are not subclasses of some parent class, they are not subclasses of each other. They are absolutely different and in fact are black boxes for each other. So, the idea of T extends Something does not work, because there is nothing to extend. Though, I've provided a semi-pseudo example, in an answer I wish to see a real class - and for simplicity let it be generalized on two arbitrary classes. Thanks!