Lets assume i have 2 totally different user-defined classes A and B.
A a = new A();
B b = new B();
. . .
. . .
a = (A) b; //I'm pretty sure this raises a ClassCastException, but how to deal with this issue?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t, unless B derives from A.
That’s the point of a ClassCastException.
But since A and B are totally different, why would you want to convert them in the first place?