英文:
How to create a List which of type Activity in android
问题
如何创建一个类型为Activity的List?
英文:
List<Activity> allowedActivites = new ArrayList<>();
allowedActivites.add(SplashActivity.class);
allowedActivites.add(SubscriptionActivity.class);
How to create a List which is of type activity?
答案1
得分: 2
你尝试添加到列表的项目是类。如果你想要一个扩展Activity
的类的列表,类型是List<Class<? extends Activity>>
。
所以你可以这样做:
List<Class<? extends Activity>> allowedActivites = new ArrayList<>();
allowedActivites.add(SplashActivity.class);
allowedActivites.add(SubscriptionActivity.class);
只要它们是Activity
的子类。
英文:
The items that you're trying to add to your list are classes. If you want a list of classes that extend Activity
, the type is List<Class<? extends Activity>>
.
So you can do
List<Class<? extends Activity>> allowedActivites = new ArrayList<>();
allowedActivites.add(SplashActivity.class);
allowedActivites.add(SubscriptionActivity.class);
as long as those are subclasses of Activity
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论