0
出於好奇。我怎樣才能創建一個新的類,其中構造函數不需要參數?這裏有一個例子:如何從類<?>創建新班級?
public static BroadcastReceiver startBroadcastReceiver(Context context, Class<?> receiverClass, String receiverTag) {
BroadcastReceiver receiver = null;
IntentFilter intentFilter = new IntentFilter(receiverTag);
receiver = new receiverClass(); // <---- What's the correct syntax?
if (receiver != null && intentFilter != null) {
context.registerReceiver(receiver, intentFilter);
}
return receiver;
}
這是我會怎麼稱呼它:
MyTools.startBroadcastReceiver(context, MyBroadcastReceiver, MyBroadcastReceiver.TAG);
在此先感謝。
'receiverClass.newInstance();'? – assylias
您想要創建類的* class *或new * object *嗎? – Pshemo