【发布时间】:2021-04-05 02:19:02
【问题描述】:
这是我的代码,我想使用多态但是 getPartActionList 是静态的,我不使用多态性。 此方法返回参数名称 PartAction 类,它对所有对象的行为都相同。 getPartActionList 方法在我的代码中应该是静态的还是非静态的? 请帮我。 很抱歉写得不好。
public class PartAction extends BaseAction {
private String address;
private String brand;
private String part_human;
public static List<String> getPartActionList() {
List<String> list = new ArrayList<>();
list.add("addressName");
list.add("brandName");
list.add("partHumanName");
return list;
}
switch (categoryEnums) {
case MAIN_CATEGORY:
recyclerViewCategory.setAdapter(new CategoryAdapter(getContext(),getMainCategory(), statusFragment, childFragmentManager));
break;
case BUY_CATEGORY:
recyclerViewCategory.setAdapter(new SubcategoryAdapter(getContext(), BuyAction.getBuyActionList(), statusFragment, childFragmentManager,action));
break;
case HUMAN_CATEGORY:
recyclerViewCategory.setAdapter(new SubcategoryAdapter(getContext(), HumanAction.getHumanActionList(), statusFragment, childFragmentManager,action));
break;
case HUMAN_SUBCATEGORY_1:
recyclerViewCategory.setAdapter(new SubcategoryAdapter(getContext(), HumanAction.getSubCategoryHumanList(), statusFragment, childFragmentManager,action));
break;
case HUMAN_SUBCATEGORY_2:
recyclerViewCategory.setAdapter(new SubcategoryAdapter(getContext(), HumanAction.getSecondSubCategoryHumanList(), statusFragment, childFragmentManager,action));
break;
case SERVICE_CATEGORY:
recyclerViewCategory.setAdapter(new SubcategoryAdapter(getContext(), ServiceAction.getServiceActionList(), statusFragment, childFragmentManager,action));
break;
case TRANSPORT_CATEGORY:
FragmentTransaction fragmentTransaction = childFragmentManager.beginTransaction();
fragmentTransaction.add(R.id.framLayout_child_category, new HomeFragment("حمل و نقل", action));
fragmentTransaction.addToBackStack(null).commit();
break;
case REPAIRS_CATEGORY:
recyclerViewCategory.setAdapter(new SubcategoryAdapter(getContext(), RepairAction.getRepairActionList(), statusFragment, childFragmentManager,action));
break;
case PARTS_CATEGORY:
recyclerViewCategory.setAdapter(new SubcategoryAdapter(getContext(), PartAction.getPartActionList(), statusFragment, childFragmentManager,action));
break;
【问题讨论】:
-
请展示一些使用 PartAction 类的示例代码,并解释您期望从中得到什么输出。
-
我上传了一张照片。
-
请编辑您的问题并将您的代码放入其中。截图太难阅读,不允许我们编译代码。
-
我在上面不同的地方使用了这段代码。
标签: java methods static polymorphism