Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

dynamic casting in java

810787Nov 5 2010 — edited Nov 6 2010
Hello everyone....



i am having a problem as follows:

i have a method in my project which is taking a reference of object type...
i want to cast the object to the passing type,bt i dont want to cast explictily inside the method...

can something be done by which the object itself get casted to passing type automatically by determining the runtime of the instance being passesd at runtime?


public void change(Object o)
{
/// i want to cast this object to A type without explicit casting.... can it be done through reflection or some other method?
}

call of the above method from main///


p.s.v.main(String[] args)
{

A a =new A();
a.call(new A());

}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 4 2010
Added on Nov 5 2010
9 comments
2,194 views