Asit Shukla

Greenhorn
+ Follow
since Sep 30, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Asit Shukla

@Paul

See if the code line was

Then there are no issues.This code will compile and run fine but in the scenario which i described is different. Here the class TestInterfaceImpl does not extends TestClassCast, just implements the TestInterface. Here it is obvious that at runtime a class cast exception will be thrown but compiler does not complain at compile time. My question is that why does compiler still allows typecasting when it is evident that TestClassCast is unrelated to TestInterface(Does not implement it).If I make the TestClassCast final the compiler *does* report a compilation error. Just because of the possibility that there could be a child class of TestClassCast which also implement TestInterface?

Thanks,
Asit
16 years ago
But Why does java allow this? Why does it allow casting an interface to any class just for the possibility that there could be a child class of the class the interface is being cast to which could implement the Interface?!! Again pasted some code below.




Thanks,
Asit

16 years ago
Please help me understand that while casting List to any user defined object (which doesnt falls in hierarchy of List even), why compiler doesn't reports a compiletime error?


Thanks,
Asit

16 years ago