• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

equals()

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just found out that StringBuffer does not override the equals() method and that the Object version returns true only if they point to the same object(like ==).
What classes(if any) besides String override equals?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All of the "wrapper" classes provide a custom version of equals, as far as I know. It is instructive to examine the equals methods in the libaray classes - for instance, here is the method in the Float class.

public boolean equals(Object obj) {
return (obj != null)
&& (obj instanceof Float)
&& (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
}
Bill
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But i think Void (java.lang.Void) is also a wrapper class
but it doesn't provide custom version of equals. this kind of question must be ans false in the SCJP exam .
Example--->
All of "Wrapper" classes override equals ?
The ans is obvious false.
(this is only for information although i am 100% agree with your reply sir)

Originally posted by William Brogden:
All of the "wrapper" classes provide a custom version of equals, as far as I know. It is instructive to examine the equals methods in the libaray classes - for instance, here is the method in the Float class.

public boolean equals(Object obj) {
return (obj != null)
&& (obj instanceof Float)
&& (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
}
Bill


 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that is what I expected as String and the Wrapper classes also share the trait of being immutable.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Even the Date and the File class overide equals
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just wondering, is Void a wrapper class? Its not specified explicitly as for all other wrapper classes in the API.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
java.lang.Void is a wrapper class that wraps objects of primitive type "void".
http://java.sun.com/products//jdk/1.2/docs/api/java/lang/Void.html
- Suresh Selvaraj
 
Govinda
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by lakshmi nair:
Just wondering, is Void a wrapper class? Its not specified explicitly as for all other wrapper classes in the API.


probabely you have not studied Java API Lakshmi Nair
here is what given in api (update your knowledge...)
(and void is primitive data type as int , long, double , float , char, boolean , byte
probabely you will face the utility of primitive void and "Wrapper" Void in Beans.)
java.lang
Class Void
java.lang.Object
|
+--java.lang.Void
--------------------------------------------------------------------------------
public final class Void
extends Object
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.

Since:
JDK1.1

[This message has been edited by Govinda (edited November 26, 2000).]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic