@@ -536,18 +536,49 @@ public static <A, B> Equal<Writer<A, B>> writerEqual(Equal<A> eq1, Equal<B> eq2)
536536
537537 /**
538538 * @return Returns none if no equality can be determined by checking the nullity and reference values, else the equality
539+ * @deprecated see issue #122.
539540 */
541+ @ Deprecated
540542 public static Option <Boolean > shallowEqualsO (Object o1 , Object o2 ) {
541543 if (o1 == null && o2 == null ) {
542544 return Option .some (true );
543545 } else if (o1 == o2 ) {
544546 return Option .some (true );
545547 } else if (o1 != null && o2 != null ) {
546548 java .lang .Class <?> c = o1 .getClass ();
549+ // WARNING: this may return some(false) for two instance of same type (and thus comparable) but of different class (typicaly anonymous class instance).
547550 return c .isInstance (o2 ) ? Option .none () : Option .some (false );
548551 } else {
549552 return Option .some (false );
550553 }
551554 }
555+
556+ /**
557+ * Helper method to implement {@link Object#equals(Object)} correctly. DO NOT USE it for any other purpose.
558+ *
559+ * @param clazz the class in which the {@link Object#equals(Object)} is implemented
560+ * @param self a reference to 'this'
561+ * @param other the other object of the comparison
562+ * @param equal an equal instance for the type of self (that use {@link #anyEqual()} if generic type).
563+ * @return true if self and other are equal
564+ */
565+ @ SuppressWarnings ("unchecked" )
566+ public static <A > boolean equals0 (final java .lang .Class <? super A > clazz , final A self , final Object other , final Equal <A > equal ) {
567+ return self == other || clazz .isInstance (other ) && equal .eq (self , (A ) other );
568+ }
569+
570+ /**
571+ * Helper method to implement {@link Object#equals(Object)} correctly. DO NOT USE it for any other purpose.
572+ *
573+ * @param clazz the class in which the {@link Object#equals(Object)} is implemented
574+ * @param self a reference to 'this'
575+ * @param other the other object of the comparison
576+ * @param equal a lazy equal instance for the type (that use {@link #anyEqual()} if generic type)..
577+ * @return true if self and other are equal
578+ */
579+ @ SuppressWarnings ("unchecked" )
580+ public static <A > boolean equals0 (final java .lang .Class <? super A > clazz , final A self , final Object other , final F0 <Equal <A >> equal ) {
581+ return self == other || clazz .isInstance (other ) && equal .f ().eq (self , (A ) other );
582+ }
552583
553584}
0 commit comments