pratik gaurav wrote:why is the toString method kept in Object class ?
though it is a method to return the Object in form of a String
why not kept in any of 4 classes of String
OCPJP
pratik gaurav wrote:why is the toString method kept in Object class ?
though it is a method to return the Object in form of a String
why not kept in any of 4 classes of String
The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
If it was only for String class then how would we get some meaningful name for our custom made classes object and other Java Objects other than String.
Getting??
If toString was not defined in the Object class then we would always get some hashcode values.
Abdulla S Mamuwala wrote:
I don't think it is necessary to use toString() from Object class to get meaningful information about your object.
For example,
As you can see toSting() would infact give bad info. I am sure you meant to give a different explanation?
As you can see toSting() would infact give bad info.
Abdulla S Mamuwala wrote:What are the 4 classes of String you referring to? All the while I was thinking that String was only one class?
http://docs.oracle.com/javase/6/docs/api/java/lang/String.html
Anyways, you have a valid question!
No, no, no, no, no.pratik gaurav wrote: . . .
the 4 classes are
1. java.lang.String
2. java.lang.StringBuffer
3. java.lang.StringBuilder
4. java.lang.StringTokenizer
Abdulla S Mamuwala wrote:Hi Jeff, looks like you have missed the point I was making to Ishan. I am by no means proposing to use description() method instead of toString(), I am just saying that there is another alternative we can use instead of toString(), although it might not be the best objective oriented practice.
"We can make any old method we want on our classes that returns a String that describes the object," well, yes, that's true, but it's not particularly relevant or useful.
I don't think it is necessary to use toString() from Object class to get meaningful information about your object.
If toString was not defined in the Object class then we would always get some hashcode values.
Abdulla S Mamuwala wrote:Hi jeff, sorry but I would disagree,
"We can make any old method we want on our classes that returns a String that describes the object," well, yes, that's true, but it's not particularly relevant or useful.
May be in one scenario it is not relevant but in others it might be?
say my client wants to use the Car class I built and wants to know the description of the car from the Car object he builds. He prefers to know this description by calling a method named "description" which is more english like and more intuitive then "toString()". Then should I force him to use toString()
A programmer will not be put off by toString() vs. description(). We're not creating libraries for non-programmers here.
The point, in relation to the topic of this thread, is (and this has been stated a couple of times): We want to have a method that we can call on any object, without knowing what kind of object it is or what special methods it may have added for itself. I'm not saying we can't add other specialized methods to our classes. What I AM saying is that those methods are not a replacement for toString().
Abdulla S Mamuwala wrote:Anyways, nitpicking is not going to help anyone.
pratik gaurav wrote:why is the toString method kept in Object class ?
though it is a method to return the Object in form of a String
why not kept in any of 4 classes of String
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Abdulla S Mamuwala wrote:Truly, I thought I was communicating with a human and not a computer!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Here's the question you should answer: why should it not be on Object?
One of his maxims was: 'Invert, always invert' ('man muss immer umkehren'), expressing his belief that the solution of many hard problems can be clarified by re-expressing them in inverse form.
Abdulla S Mamuwala wrote:Truly, I thought I was communicating with a human and not a computer!
dictionary
Definitions on nitpicking,
verb (used without object)
1. to be excessively concerned with or critical of inconsequential details.
verb (used with object)
say my client wants to use the Car class I built and wants to know the description of the car from the Car object he builds. He prefers to know this description by calling a method named "description" which is more english like and more intuitive then "toString()". Then should I force him to use toString()
Abdulla S Mamuwala wrote:This kind of thinking can really help solve a lot of problems even when applied to this question.
...
One of his maxims was: 'Invert, always invert' ('man muss immer umkehren')
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
sourav jain wrote:if object class is not is super class in java , you cannot synchronize the threads in java programs because Thread class inherits methods are (wait , notify(), notifyall())
3) there different forms of tostring methods are
- tostring() : without args
- toXXXString() : static methods for collection(java .utill)
- tostring(int i , int radix ) these method used for convert int to (binary , oct, hex)
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |