What is SuppressWarnings (“unchecked”) in Java?

前端 未结 11 585
轮回少年
轮回少年 2020-11-22 12:48

Sometime when looking through code, I see many methods specify an annotation:

@SuppressWarnings(\"unchecked\")

What does this mean?

11条回答
  •  清酒与你
    2020-11-22 13:18

    You can suppress the compiler warnings and tell the generics that the code which you had written is legal according to it.

    Example:

    @SuppressWarnings("unchecked")
    public List retreiveMealPlan() {
         List list=new ArrayList();
        TestMenuService testMenuService=new TestMenuService(em, this.selectedInstance);
        list = testMenuService.getMeal(reservationMealPlan);
        return list;
     }
    

提交回复
热议问题