Constructor equals() method in Java with Examples
The constructor class provides information about a single constructor for a class and it also provides access to that constructor.
The equals() method of java.lang.reflect.Constructor is used to compare this Constructor against the passed object. If the objects are the same then the method returns true. In java Two Constructor objects are the same if and only if they were declared by the same class and have the same formal parameter types.
public boolean equals(Object obj)
Parameters: This method accepts obj which is the reference object with which to compare.
Return: This method returns true if this object is the same as the obj argument. Else it returns false.
Below programs illustrate equals() method:
Constructor 1: public java.lang.String(byte, int, int) Constructor 2: public java.lang.String(byte, java.nio.charset.Charset) Both constructor are equal: false
Constructor 1: public java.util.ArrayList(java.util.Collection) Object: public java.util.ArrayList(java.util.Collection) Both constructor are equal: true