代码中有4个PhoneStateListener构造函数,但只有一个被公开,其他被隐藏如下:
public PhoneStateListener() {
this(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, Looper.myLooper());
}
/**
* Create a PhoneStateListener for the Phone with the default subscription
* using a particular non-null Looper.
* @hide
*/
public PhoneStateListener(Looper looper) {
this(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, looper);
}
/**
* Create a PhoneStateListener for the Phone using the specified subscription.
* This class requires Looper.myLooper() not return null. To supply your
* own non-null Looper use PhoneStateListener(int subId, Looper looper) below.
* @hide
*/
public PhoneStateListener(int subId) {
this(subId, Looper.myLooper());
}
/**
* Create a PhoneStateListener for the Phone using the specified subscription
* and non-null Looper.
* @hide
*/
public PhoneStateListener(int subId, Looper looper) {
....
....
请问如何在我的代码中使用隐藏构造函数的控制器反射?
public final class MyStateListener extends PhoneStateListener {
private static final String TAG = "MyStateListener ";
public MyStateListener(Context c) {
int subId = 1;
Looper looper = c.getMainLooper();
super(subId, looper); // <-- this is hidden constructor so I want to replace this into constructor refrection.
....
....
而不是超级(subId,looper),是否可以接受?如果没有,任何好主意?
this.getClass().getSuperclass().getConstructors()[2].newInstance(1, c.getMainLooper());