Originally posted by jiju ka: A narrowing conversion is not detected at compile time. It is detected only at runtime. At Runtime you will get a ClassCastException.
In the above code you can see that an instance of Object is wider than an instance of A. Similarly A is wider than B. But the compiler don't know about which type is wider than which or vice versa.
I think the OP is asking why the compiler is so stupid! Why doesn't the compiler know -- it is pretty obvious in these two cases.
The problem is that in other cases it's very hard to determine if a cast will fail or succeed. And in general, it's undecidable. Because of that, compiler give up right way and don't try to deduce if a cast will fail -- they typically don't give you a heads-up warning, for example.
There is no emoticon for what I am feeling!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com