Intellij Warning - General Unchecked Task

Possible duplicate:
Java Generics, how to avoid unchecked task warning when using class hierarchy?

Intellij gives me a warning below. Not sure how to solve it, or even if I need to solve it. The warning information says that this only applies to JDK 5, and I'm using 6. I'm wondering if I need to respond to this, and if so, how?

Method call

List<T> refObject = cache.getCachedRefObject(cacheKey, List.class); 

Method called

 public <T> T getCachedRefObject(String objectKey, Class<T> type) { return type.cast(refObjectCache.get(objectKey)); } 

Warning Information

 Unchecked Assignment JDK 5.0 only. Signals places where an unchecked warning is issued by the compiler, for example: void f(HashMap map) { map.put("key", "value"); } 
+4
source share
2 answers

When playing with supertype tokens for this, I don’t think that you can do this type of security without additional methods for extracting collections from your cache and verifying that their contents are correct.

Your options:

  • Doing the above that seems time consuming.
  • Suppress uncontrolled selection in client code if you know it correctly.
  • Replace the client code with List<?> refObject = cache.getCachedRefObject(cacheKey, List.class);

The only type of safe option is 3. because it prevents you from performing operations that the compiler cannot prove, it is type safe. The obvious downside is that you might want to perform some of these operations.

0
source

It looks like you have an old version of IntelliJ. This warning really means that Java 5.0+ and AFAIK were changed when IntelliJ supported Java 6, so the warning was there, but did not say only β€œJDK 5.0” (now it supports Java 8)

+3
source

Source: https://habr.com/ru/post/1435942/


All Articles