There are two types of casts in Java - upcasting and downcasting.
There are two phases of code execution in Java - compilation and execution.
Compilation checks things like syntax and making sure there aren't any glaring errors.
Execution actually executes the codes and if there is something wrong it will throw an exception.
You can always do an upcast without any error.
However, downcasting can be risky. There are two types of cases when downcasting can be risky. Case #1: You downcast an Object to a String, for example. This can be risky because not all objects are strings. However, the compiler can easily check this by making sure the object that the reference variable points to is a String. This applies to your question because you downcast safely so the compiler is happy.
Case #2: You have generics. In the case of generics, during compile time, the compiler does not know what the type is, so it cannot ensure that the casting will work fine. This is when it will throw a warning. If the casting does not work fine, a ClassCast exception will be thrown during runtime.