Home How to reinstantaite Object arrays in implemented class of Interfaces?
Reply: 0

How to reinstantaite Object arrays in implemented class of Interfaces?

user1325 Published in June 19, 2018, 11:55 pm

I have a Interface I which has a static function returnbjectsCreated()

Initially class A and B implemented I

But I want to keep track of the objects created.

So I created a class C that implements I ; A and B extends C I thought of appending the array in defObj[] in the constructor of C but didn't work as it was final.

    public interface I
        DefObj[] defObj;

     public static DefObj[] returnCreatedObjArr()
    return defObj;

Each time I create a new object for A or B, it needs to be appended to defObj in the interface.

i.e when I access I.returnCreatedObjArr() it should return all objects created.

What should I do ?

Note: No external packages or java collections can be used

Can you please add a snippet of that? The trouble I am facing right now is as follows :

private Node[] updateDefObj()
        DefObj[] new DefObj = new DefObj[defObj.length + 1];
        System.arraycopy(defObj.length, 0, new defObj.length, 0, defObj.length);
        defObj.[defObj.length+1] = this;
        return defObj.length;

class constructor:
     C() {

        defObj = new DefObj.length[defObj.length + 1] ;
        defObj = updateDefObj(defObj);  }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305142 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO