toString() method be always used in place of (String) cast

classic Classic list List threaded Threaded
2 messages Options
Ankur Ankur
Reply | Threaded
Open this post in threaded view
|

toString() method be always used in place of (String) cast

Can toString() method be always used in place of (String) cast. Can anybody give me an example where this can not happen in JAVA.
buggybread buggybread
Reply | Threaded
Open this post in threaded view
|

Re: toString() method be always used in place of (String) cast

toString returns the String representation of any object. It calls the overridden method of the respective object to get the string representation. String and other classes have implemented that method properly and hence you get the proper string representation. Casting just specify the compiler to read the respective value differently and there is no function call. If your pupose is to cast, use casting only.
www.buggybread.com