equals Questions
9
Solved
How should model class's equals and hashcode be implemented in Hibernate? What are the common pitfalls? Is the default implementation good enough for most cases? Is there any sense to use business ...
17
Solved
I constructed a class with one String field. Then I created two objects and I have to compare them using == operator and .equals() too. Here's what I've done:
public class MyClass {
String a;
...
7
Solved
I have these data transfer objects:
public class Report
{
public int Id { get; set; }
public int ProjectId { get; set; }
//and so on for many, many properties.
}
I don't want to write
publi...
9
Solved
I ran into an interesting (and very frustrating) issue with the equals() method today which caused what I thought to be a well tested class to crash and cause a bug that took me a very long time to...
Doriandoric asked 9/10, 2008 at 4:22
77
Solved
A strict equality operator will tell you if two object types are equal. However, is there a way to tell if two objects are equal, much like the hash code value in Java?
Stack Overflow question Is ...
Pariah asked 14/10, 2008 at 13:41
6
Solved
I have a class that accepts a generic type, and I want to override the equals method in a non-awkward way (i.e. something that looks clean and has minimal amount of code, but for a very general use...
4
Solved
Here are my requirements for unit testing:
I would like to unit test my production classes
I would like to separate test code and production code apart such that I can release production code onl...
Procuration asked 13/8, 2013 at 17:24
2
I have a enum class as follows.
public enum Item {
COKE("Coke", 25), PEPSI("Pepsi", 35), SODA("Soda", 45);
private String name;
private int price;
private Item(String name, int price) {
this....
5
Solved
I have one BaseEntity which abstracts id and version property. this class also implements hashcode and equals based on PK (id) property.
BaseEntity{
Long id;
Long version;
public int hashCod...
10
Solved
Basically, GethashCode is different even though they contain the SAME values for the properties... so why is the default to return diff hashcodes?
public class User
{
public Int32 Id { get; set; ...
1
Java hash code generation code often uses prime numbers in its calculations. There are good reasons for this, as explained in Why use a prime number in hashCode? and elsewhere.
For example, AutoVal...
Bimonthly asked 27/6, 2018 at 23:14
6
Solved
Given some arrays in Kotlin
let a = arrayOf("first", "second")
val b = arrayOf("first", "second")
val c = arrayOf("1st", "2nd")
Are there built-in functions to the Kotlin std-lib that tests two ...
5
Solved
I've currently got an overridden equals(Object) that looks like this:
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (! (o instanceof Player)) return false;
Player p...
Constantina asked 26/3, 2013 at 3:23
9
Solved
If I have a object like:
public class Person
{
public int id {get;set;}
public string name {get;set;}
}
And I want the behavior:
Person a = new Person();
Person b = new Person();
a == b;
a...
3
Solved
Is there a an implementation of the HashMap class (or Map interface) that will allow me to use alternate hashcode and equals operations...
Similar to how collections of the same type can be sorted ...
Auston asked 3/3, 2013 at 10:19
6
Solved
I need to compare two objects of the same class excluding some fields.
public final class Class1 {
private String a;
private String b;
private String c;
:
:
:
private String z;
private Date c...
4
Solved
I am a bit puzzled about the behaviour of SortedSet, see following example:
public class Blah
{
public double Value { get; private set; }
public Blah(double value)
{
Value = value;
}
}
publ...
15
I have problems finding a solution to an SQL query. This is probably a very obvious beginner question but I can't seem to get the results that I'm after. I have a table that looks something like th...
7
I need to compare two strings which represent json objects. For testing purposes I need a way to compare these strings ignoring not only the child elements order (which is quite common) but order o...
Kreplach asked 11/11, 2011 at 19:26
28
I want to perform some action ONLY IF my string has a meaningful value. So, I tried this.
if (!myString.equals("")) {
doSomething
}
and this
if (!myString.equals(null)) {
doSomething
}
and th...
Exhibitionist asked 8/4, 2010 at 17:15
5
Solved
I have the following data class
data class PuzzleBoard(val board: IntArray) {
val dimension by lazy { Math.sqrt(board.size.toDouble()).toInt() }
}
I read that data classes in Kotlin get equals()/...
Siler asked 30/5, 2016 at 11:21
20
Solved
I have a condition in a silverlight application that compares 2 strings, for some reason when I use == it returns false while .Equals() returns true.
Here is the code:
if (((ListBoxItem)lstBaseMe...
6
MySQL provides a nice operator <=> that works with comparisons that could contain a null such as null <=> null or null <=> 5 etc. giving back intuitive results as many programming...
Unsettled asked 5/4, 2012 at 23:13
11
Solved
I am trying to override equals method in Java. I have a class People which basically has 2 data fields name and age. Now I want to override equals method so that I can check between 2 People object...
Unintelligent asked 18/11, 2011 at 9:41
3
I have exactly the problem described here. This is, being BigDecimal's equals being broken as it is, having such a field in a class prevents using @EqualsAndHashCode. The only solution I came up wi...
Embroideress asked 14/4, 2016 at 13:56
1 Next >
© 2022 - 2025 — McMap. All rights reserved.