简体   繁体   中英

@SuppressWarnings(“unchecked”) in dao classes

Java documentation says:

As a matter of style, programmers should always use this annotation on the most deeply nested element where it is effective. If you want to suppress a warning in a particular method, you should annotate that method rather than its class.

I didn't really feel any benefits of using this annotation. But its not really hard to put it everywhere. Should I use it for all methods of the dao classes that interact with the Hibernate (getting and saving some data)?

You might even want to use it on idividual fields, for example:

@SuppressWarnings("unchecked") List l = query.list();

As the doc says, use it at the lowest possible level in order to avoid hiding the warning in situations where it should not be suppressed, that you can fix through propery use of generics (in the example above you can't since HQL-based queries don't support generics (yet) ).

Warnings in code are those issue which can not affect the code execution means you can run your code even you have lots of warning. But these may affect your code performance.

When you know about the specific warning and its disadvantages and due to some reason if it is not possible to avoid these warning in your project then you can use @SuppressWarnings.

@SuppressWarnings will ignore the warning specified and feel that you already aware of this warning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM