code21
code21

Reputation: 11

Instantiate a static abstract class through reflections

public class FingerprintManager {

     * @hide
     */
   // this class is hidden 
    public static abstract class EnrollmentCallback {

        public void onEnrollmentError(int errMsgId, CharSequence errString) { }


        public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) { }


        public void onEnrollmentProgress(int remaining) { }
    };
}

EnrollmentCallback class is hidden.Is there a way to instantiate EnrollmentCallback class through reflection which is equivalent to :

EnrollmentCallback callbackObject = new EnrollmentCallback ()
{
        public void onEnrollmentError(int errMsgId, CharSequence errString) { }


        public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) { }


        public void onEnrollmentProgress(int remaining) { }
};

Upvotes: 1

Views: 95

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201497

No. It might be possible to do that with a byte-code manipulation library (like ASM), but it's not possible to instantiate an abstract class without extending it and implementing any missing (abstract) methods. And you can't do that with Java reflection.

Upvotes: 2

Related Questions