aspose file tools*
The moose likes Beginning Java and the fly likes equals() method of java.util.Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "equals() method of java.util.Arrays" Watch "equals() method of java.util.Arrays" New topic
Author

equals() method of java.util.Arrays

Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178


Dear friends,
The above statement gives compiler error. In the API there is one overloaded equals() method which takes two Object arrays as parameters.

Kindly explain the concept hidden in the above statement.

Regards,
Vijay
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Have you read the API specification for Arrays? It is overloaded as equals(int[], int[]) or equals(Object[], Object[]), but not as equals(int[], Object[]).

Unboxing will not convert int[] to Integer[] or vice versa. You will have to extend Arrays (it's not final) and implement an overridden equals(int[], Integer[]) method.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

Originally posted by Campbell Ritchie:
... You will have to extend Arrays (it's not final) and implement an overridden equals(int[], Integer[]) method.

Class java.util.Arrays is indeed not final, but it has a private constructor, so you cannot extend it anyway. It's not meant to be instantiated or extended; it's just a bunch of static utility methods.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178
Dear Jesper & Campbell,
Thanks for the reply


Regards,
Vijay
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Sorry, I hadn't noticed the private constructor. You are right; it won't work with a private constructor. You would have to create your own MyArrays class with an equals(int[], Integer[]) method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: equals() method of java.util.Arrays