Cho em hỏi chức năng của annotation @SuppressWarnings({“unchecked”, “rawtypes”}), và khi nào thì mình nên dùng nó ạ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
1. unchecked: sử dụng trong trường hợp em cast mà không sử dụng `instanceof`
Ví dụ:
Object obj = new String(“abc”);
String str = (String)obj; thì khả năng cao em sẽ bị cảnh báo còn nếu em check:
if(obj instanceof String) {
String str = (String)obj;
}
thì ok
2. rawtypes: sử dụng trong trường hợp em không chỉ định rõ generic type cho lớp em dùng
Ví dụ: List list = new ArrayList() thì em sẽ bị IDE cảnh báo còn nếu em dùng List list = new ArrayList() thì không sao