Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BaseClass {
- //
- }
- class SubClass extends BaseClass{
- //
- }
- class Transformer{
- BaseClass base;
- public Transformer(BaseClass base){
- this.base = base;
- }
- public void transform(){
- //transforms the Object to a subtype-object
- // ???
- this.base = new SubClass(); //something like this (but not so!!!)
- }
- }
- class Programm{
- private List<BaseClass> list1 = new ArrayList<>();
- private List<BaseClass> list2 = new ArrayList<>();
- private List<BaseClass> list3 = new ArrayList<>();
- //many more Lists
- private List<BaseClass> listn = new ArrayList<>();
- public void main() {
- BaseClass myObject = new BaseClass();
- list1.add(myObject);
- list2.add(myObject);
- list3.add(myObject);
- listn.add(myObject);
- Transformer transformer = new Transformer(myObject);
- transformer.transform();
- //required result
- // All Lists contain the transformed Object (from Type SubClass)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement