jeudi 11 août 2016

Find private inner class using reflection

In the context of android.accounts.AccountManager:

public class AccountManager {

    private abstract class AmsTask extends FutureTask<Bundle> implements AccountManagerFuture<Bundle> {
    ...
    }

}

I would like to find the inner class using reflection by name. In the simple case

public class AccountManager {

    public class Foo {
    ...
    }

}

This can be done using Class.forName("android.accounts.AccountManager$Foo"). However, the private modifier eliminates this possibility. I tried searching through Class.forName("android.accounts.AccountManager").getDeclaredClasses(), but it returns an empty list. Its specification covers private member classes, so I am at a loss why it is not returned by the getter. I presume it has something to do with abstract.





Aucun commentaire:

Enregistrer un commentaire