mercredi 21 mars 2018

java reflection - find reference holders

Let's say I have a long array that I know is stored in exactly one field somewhere.

e.g.

class Foo{
    public long[] foo = new long[12];
}

class Bar{
    public long[] foo = new long[12];
}

What I do not know is what class that field belongs to. Is there any way to find out?

I.e. I want a method

String isFooOrBar(long[] arr){
    return someMagic();
}

that will return "Foo" for

long[] arr = new Foo().foo;
isFooOrBar(arr);

and "Bar" for

long[] arr = new Bar().foo;
isFooOrBar(arr)

Is there a way to get the names of all classes that hold a reference to the array in a field?





Aucun commentaire:

Enregistrer un commentaire