1

This is the Code i found in a book:

list = new ArrayList();
list.add( "SuppressWarnings" );

So in Eclipse, this code gave me those warnings:

Note: ABC.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

But as i tried it in Intellij, everything was fine. Whats the problem with this code and what is this code doing, cause that was not described in my book?

hallo545401
  • 115
  • 13
  • 1
    Does this answer your question? [What is a raw type and why shouldn't we use it?](https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it) – OH GOD SPIDERS Mar 05 '20 at 13:20
  • Or Alternativly: [What causes javac to issue the “uses unchecked or unsafe operations” warning](https://stackoverflow.com/questions/197986/what-causes-javac-to-issue-the-uses-unchecked-or-unsafe-operations-warning) – OH GOD SPIDERS Mar 05 '20 at 13:23
  • The first one does not, I already know, why there is a raw type warning. As i recompiled it with -Xlint i goth other warnings: warning: [unchecked] unchecked call to add(E) as a member of the raw type ArrayList list1.add("SuppressWarnings"); ^ where E is a type-variable: E extends Object declared in class ArrayList (I left the ones with raw type away) And this warning I don't understand. – hallo545401 Mar 05 '20 at 13:26
  • The warning happens because you are using a raw type and adding to a raw type is an unsafe operation. I'm not sure why this doesn't answer the question. – OH GOD SPIDERS Mar 05 '20 at 13:33
  • Now I do understand. Thanks for the help. – hallo545401 Mar 05 '20 at 15:11

0 Answers0