in Education by
I use Eclipse for java, this is the error is got. Type safety: Unchecked cast from Object to HashMap Now there is another that I get from a call to an API that I have no control over returns HashMap getItems(javax.servlet.http.HttpSession session) { HashMap theHash = (HashMap)session.getAttribute("attributeKey"); return theHash; } I would like to avoid Eclipse warnings, if possible. I read somewhere I could use SupressWarning to do it, what is it and how to use it? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
SuppressWarning @SuppressWarnings instruct the compiler to ignore or suppress the specified compiler warning in annotated element and all program elements inside that element, as an example, if a class is annotated to suppress a particular warning, then a warning generated during the methodology inside that class will also be suppressed. @SuppressWarnings("unchecked") and @SuppressWarnings("serial") are two of most popular samples of @SuppressWarnings annotation. Also if you limit the scope, this way it won’t even affect the entire method. SuppressWarnings indicates the potential programming error or mistake, so it's recommended to use them slenderly and instead attempt to solve actual problem which is triggering that warning. But there are situations when you are absolutely sure that things won't go wrong, you can use @SuppressWarnings to suppress those warnings.

Related questions

0 votes
    What are generic methods? (a) Generic methods are the methods defined in a generic class (b) Generic methods ... Generics of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Which of these type parameters is used for a generic methods to return and accept any type of object? (a) ... chapter Generics of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Which of these type parameters is used for a generic methods to return and accept a number? (a) K (b) N ... in portion Generics of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Which of these is an correct way of defining generic method? (a) name(T1, T2, , Tn) { /* */ } ... topic in portion Generics of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Which of these types cannot be used to initiate a generic type? (a) Integer class (b) Float class (c) ... in section Generics of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Which of these instance cannot be created? (a) Integer instance (b) Generic class instance (c) Generic type ... Generics of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Which of these is wildcard symbol? (a) ? (b) ! (c) % (d) & I have been asked this question in ... Wildcards in section Generics of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    What is use of wildcards? (a) It is used in cases when type being operated upon is not known (b) It is ... in portion Generics of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Which of these keywords is used to upper bound a wildcard? (a) stop (b) bound (c) extends (d) ... in chapter Generics of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Which of these is an correct way making a list that is upper bounded by class Number? (a) List...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Which class represents an Internet Protocol address? (a) InetAddress (b) Address (c) IP Address (d) TCP Address ... & Servlet of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    What does local IP address start with? (a) 10.X.X.X (b) 172.X.X.X (c) 192.168.X.X (d) ... Java Server Technologies & Servlet of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    What happens if IP Address of host cannot be determined? (a) The system exit with no message (b) ... & Servlet of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    I was reading a book on programming skills wherein the author asks the interviewee, "How do you crash a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I was reading a book on programming skills wherein the author asks the interviewee, "How do you crash a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
...