0

I have to use cls variable to some method.

Class<CommonResult<Cat>> cls = (Class<CommonResult<Cat>>) ((Class) CommonResult.class);

but, this code line displays this warnings.

  • Class is a raw type. References to generic type Class should be parameterized
  • Type safety: Unchecked cast from Class to

CommonResult is generic class. I want to remove these warnings. what is the best modification to remove this warnings? I want to know a method to fix it in code level not in annotation.

user1705636
  • 233
  • 1
  • 6
  • 14
  • I don't believe the suggested duplicate was correct and I've reopened. Perhaps `@SuppressWarnings` is the only option, but I'd like to see someone explicitly state that this code can only be solved by that solution. – Duncan Jones May 13 '14 at 10:37
  • the method takes Class class parameter. so I wanted to pass cls variable. thank you in advance. – user1705636 May 13 '14 at 10:50
  • If you do not have problem with the unchecked warning, just with the raw, you can use the `(Class>)` for the inner cast. – Gábor Bakos May 13 '14 at 10:55

1 Answers1

0

I think that this question is your answer: What is SuppressWarnings ("unchecked") in Java?, as well as your question is kind of an answer for that one :-)

As for your first 2 warnings listed - The "Class is a raw type" warning might stem from the fact that you first cast to Class. Is it necessary? The second item does not read like a warning. What should "parseGetGrantedPermission(String)" be? It looks more like your method that produced the warning.

Community
  • 1
  • 1
chiccodoro
  • 14,407
  • 19
  • 87
  • 130