Is there a way to do this? Or do I have to create a class and implements IJavaElement?
Share
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 cannot cast any object of an arbitrary type to any other arbitrary class or interface type.
Casting (from one non-primitive type to another non-primitive type) does not do any magic automatic conversions. When you cast an object of type
Ato typeB, what it means is that you tell the compiler “look, I have some object of typeAhere, and I want you to treat it as if it is aB; don’t give me a type error, because I know better”.The type check will still be done, but at runtime instead of compile time. If, at runtime, the object turns out to not be a
B, you’ll get aClassCastException.Assuming you’re talking about class
java.lang.Class, then no, you cannot cast that toIJavaElement(wherever that comes from) becauseIJavaElementis not a superclass of nor an interface implemented byjava.lang.Class. If you try to do the cast, you’ll get aClassCastExceptionwhen you run your program.