equality

Why String.Equals is returning false?

本小妞迷上赌 提交于 2019-11-28 09:41:01
I have the following C# code (from a library I'm using) that tries to find a certificate comparing the thumbprint. Notice that in the following code both mycert.Thumbprint and certificateThumbprint are strings. var certificateThumbprint = AppSettings.CertificateThumbprint; var cert = myStore.Certificates.OfType<X509Certificate2>().FirstOrDefault( mycert => mycert.Thumbprint != null && mycert.Thumbprint.Equals(certificateThumbprint) ); This fails to find the certificate with the thumbprint because mycert.Thumbprint.Equals(certificateThumbprint) is false even when the strings are equal. mycert

what happens when you compare two strings in python

半城伤御伤魂 提交于 2019-11-28 09:35:11
问题 When comparing strings in python e.g. if "Hello" == "Hello": #execute certain code I am curious about what the code is that compares the strings. So if i were to compare these in c i would just compare each character and break when one character doesn't match. i'm wondering exactly what the process is of comparing two strings like this, i.e. when it will break and if there is any difference between this comparison and the method said above other than redundancy in lines of code 回答1: I'm going

Strange behaviour of the Array type with `==` operator

人走茶凉 提交于 2019-11-28 09:17:17
scala> List(1,2,3) == List(1,2,3) res2: Boolean = true scala> Map(1 -> "Olle") == Map(1 -> "Olle") res3: Boolean = true But when trying to do the same with Array, it does not work the same. Why? scala> Array('a','b') == Array('a','b') res4: Boolean = false I have used 2.8.0.RC7 and 2.8.0.Beta1-prerelease. Because the definition of "equals" for Arrays is that they refer to the same array. This is consistent with Java's array equality, using Object.Equals , so it compares references. If you want to check pairwise elements, then use sameElements Array('a','b').sameElements(Array('a','b')) or

In which case could “a != a” return “true”?

这一生的挚爱 提交于 2019-11-28 08:54:56
问题 java.lang.Math#min(double, double): public static double min(double a, double b) { if (a != a) return a; // a is NaN if (a == 0.0d && b == 0.0d && Double.doubleToLongBits(b) == negativeZeroDoubleBits) return b; return (a <= b) ? a : b; } In which case could a != a return true ? It seems that it's when a is NaN, but I can't imagine an example. Could you please provide one? 回答1: A simple example is double d = Double.NaN; // or double d = 0.0/0.0; // or double d = Double.POSITIVE_INFINITY +

Object equality in context of hibernate / webapp

落花浮王杯 提交于 2019-11-28 07:39:58
How do you handle object equality for java objects managed by hibernate? In the 'hibernate in action' book they say that one should favor business keys over surrogate keys. Most of the time, i do not have a business key. Think of addresses mapped to a person. The addresses are keeped in a Set and displayed in a Wicket RefreshingView (with a ReuseIfEquals strategy). I could either use the surrogate id or use all fields in the equals() and hashCode() functions. The problem is that those fields change during the lifetime ob the object. Either because the user entered some data or the id changes

C# equality checking

寵の児 提交于 2019-11-28 07:02:11
What's your approach on writing equality checks for the structs and classes you create? 1) Does the "full" equality checking require that much of boilerplate code (like override Equals , override GetHashCode , generic Equals , operator== , operator!= )? 2) Do you specify explicitly that your classes model the IEquatable<T> interface? 3) Do I understand correctly, that there is no actual way to automatically apply Equals overrides, when I invoke something like a == b and I always have to implement both the Equals and operator== members? You're right, this is a lot of boiler-plate code, and you

JavaScript: {}==false is a SyntaxError?

蹲街弑〆低调 提交于 2019-11-28 06:56:06
In Firefox 3.5, I type this in the Firebug console : false=={} // => evals to false {}==false // syntax error What is the explanation for this ? bobince { at the start of a statement signals a ‘statement block’ (see ECMA-262-3 section 12.1), which contains a list of statements. } immediately ends the statement block with no statements in it. That's fine. But now the parser is looking for the next statement: ==false Huh? That's not a statement; syntax error. What are statement blocks for? Well, you are writing a statement block every time you say: if (something) { ... } JavaScript defines these

Why do comparisions between very large float values fail in python?

廉价感情. 提交于 2019-11-28 06:17:07
问题 In my understanding, sys.float_info.max is the largest possible float value. However, it seems that comparing such large values fail . import math import sys m = sys.float_info.max # type 'float' m == m # True m < m # False m > m # False m == m-1.0 # True m < m-1.0 # False m > m-1.0 # False m == m-1e100 # True m < m-1e100 # False m > m-1e100 # False m == m-1e300 # False m > m-1e300 # True m < m-1e300 # False I assume that's because of the limited precision? If so, in what numerical range can

Swift: Overriding == in subclass results invocation of == in superclass only

谁说胖子不能爱 提交于 2019-11-28 05:50:17
I've got a class A , which conforms to Equatable protocol and implements == function. In subclass B I override == with more checks. However, when I do comparison between two arrays of instances of B (which both have type Array<A> ), == for A is invoked. Of course if I change type of both arrays to Array<B> , == for B is invoked. I came up with the following solution: A.swift: internal func ==(lhs: A, rhs: A) -> Bool { if lhs is B && rhs is B { return lhs as! B == rhs as! B } return ... } Which looks really ugly and must be extended for every subclass of A . Is there a way to make sure that ==

Basic Java question: String equality

自作多情 提交于 2019-11-28 04:41:28
问题 public class A { static String s1 = "I am A"; public static void main(String[] args) { String s2 = "I am A"; System.out.println(s1 == s2); } } Above program outputs "true". Both are two different identifiers/objects how the output is "true" ? My understanding is that the JVM will create different reference for each object, if so how the output is true? 回答1: Java manages a String literal pool. It reuses these literals when it can. Therefore the two objects are actually the same String object