천재 블로그

[Spring] @suppressWarnings란? 본문

프로그래밍/Spring Framework

[Spring] @suppressWarnings란?

Dondons 2018. 4. 2. 21:10




  [Spring] @SuppressWarning(" ") 어노테이션






JSON을 사용하다가 이런 경고가 떴습니다

찾아보니 SuppressWarning 어노테이션을 사용하라고 합니다


@SuppressWarning("unchecked")
public void top3List(HttpServletResponse response) throws IOException {
 ArrayList list = pbService.selectTopList();
		
		// 전송할 최종 JSON 객체
		JSONObject json = new JSONObject();
		JSONArray jarr = new JSONArray();
		
		for(ProductBoard pb : list) {
			
			// 상세페이지 하나 씩의 정보를 저장할 json 객체 설정
			JSONObject pBoard = new JSONObject();
			pBoard.put("pbNum", pb.getPbNum());
			pBoard.put("pImg", pb.getpImg());
			pBoard.put("pName", pb.getpName());
			
			jarr.add(pBoard);
		}
		
		json.put("list", jarr);
		System.out.println(json.toJSONString());
		response.setContentType("application/json");
		PrintWriter out = response.getWriter();
		
		out.print(json.toJSONString());
		out.flush();
		out.close();
}



어노테이션 @SuppressWarnings



컴파일러가 일반적으로 경고하는 내용을 경고 금지하도록 제외시킬 때 사용합니다.

어떤 경고를 제외시킬지 옵션 부여 가능합니다.




옵션



all : 모든 경고  

cast : 캐스트 연산자 관련 경고

dep-ann : 사용하지 말아야 할 주석 관련 경고

deprecation : 사용하지 말아야 할 메서드 관련 경고

fallthrough : switch문에서 break 누락 관련 경고

finally : 반환하지 않는 finally 블럭 관련 경고

null : null 분석 관련 경고

rawtypes : 제너릭을 사용하는 클래스 매개 변수가 불특정일 때의 경고

unchecked : 검증되지 않은 연산자 관련 경고

unused : 사용하지 않는 코드 관련 경고







'프로그래밍 > Spring Framework' 카테고리의 다른 글

[Spring] @RequestParam  (0) 2018.04.08
[Spring] pom.xml 설정  (0) 2018.04.08
Comments