Bug 22141 - Equality operator not working for UUIDs, is that intentional?
Summary: Equality operator not working for UUIDs, is that intentional?
Status: RESOLVED FEATURE
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.16.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-08-16 05:32 UTC by Rogier van der Hee
Modified: 2014-08-18 15:03 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Rogier van der Hee 2014-08-16 05:32:55 UTC
I'm working with Bluetooth on Android and what has got me a couple of times is that unlike Guid1 == Guid2 in C#, in Android the equality operator is not working.

var uuid1 = UUID.FromString("0000180f-0000-1000-8000-00805f9b34fb");
var uuid2 = UUID.FromString("0000180f-0000-1000-8000-00805f9b34fb");

if(uuid1 == uuid2) 
=> will fail

if(uuid1.Equals(uuid2)) 
=> will pass

Is there a specific reason this equality operator does not work?
Comment 1 Udham Singh 2014-08-18 13:15:44 UTC
I have checked this issue and observed that "(uuid1 == uuid2)" returns value as 'false' and "(uuid1.Equals(uuid2))" gives value as 'true'. To check this issue I have followed the steps mentioned below : 

1. Create a simple android application.
2. Implement code provided in bug description.
3. Run and debug the code.

Screencast : http://screencast.com/t/21v00LE0

Environment Info :

=== Xamarin Studio ===

Version 5.2.1 (build 1)
Installation UUID: 952292e8-1484-4c56-b664-6ff701bef591
Runtime:
	Mono 3.6.0 ((no/f540f8a)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 306000039

=== Xamarin.Android ===

Version: 4.14.0 (Business Edition)
Android SDK: /Users/xamarin76/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.Mac ===

Version: 1.10.0.4 (Business Edition)

=== Xamarin.iOS ===

Version: 7.2.6.28 (Business Edition)
Hash: 606f31a
Branch: 
Build date: 2014-08-01 15:27:48-0400

=== Build Information ===

Release ID: 502010001
Git revision: d06832ce9807d6be24aca225457e8b37c7669f6f
Build date: 2014-08-07 12:10:47-04
Xamarin addins: 1de032531be4cecf2f39dbee3b87aac78204058c

=== Operating System ===

Mac OS X 10.9.3
Darwin Xamarin76s-Mac-mini.local 13.2.0 Darwin Kernel Version 13.2.0
    Thu Apr 17 23:03:13 PDT 2014
    root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64
Comment 2 Jonathan Pryor 2014-08-18 15:03:06 UTC
> Is there a specific reason this equality operator does not work?

Yes: Xamarin.Android binds Java, and Java doesn't have operator overloading, so operator== is always referential equality, not value equality.

It is possible to override operators for bound Java types, but this would be a manual process, and would introduce "incompatibilities" with any Java sample code that is being followed (if and when referential equality is actually required).