2,042 questions
18
votes
1
answer
1k
views
List<T>.ForEach does not invoke the action HashCode.Add<T>
In C#, using the structure HashCode and the List<T>.ForEach method shows a behaviour that I cannot explain:
The two snippets below do not return the same result:
Working as expected:
var ...
0
votes
2
answers
130
views
Comparing two objects using hashcode
I have a class that includes sets and optionals:
class SomeRequest{
Set<Long> longs;
Optional<String> name;
Optional<Set<Long>> opLongs;
Optional<Long> ...
0
votes
1
answer
104
views
Why are docker image hashcode non reproductible (in particular "FROM scratch") [closed]
I am building an empty image using the following Dockerfile:
FROM scratch
I tried in multiple environnements. I get either an imageID 71de1148337f or 471a1b8817ee. Why is that ? Why two different ...
-2
votes
1
answer
93
views
Define a object to be unique in a Set, irrespective of order of List elements within the given object
I have a Class B defined as below -->
Class B {
private List<String> obj1;
private List<A> obj2;
// Need to implement hashcode() and equals() methods
}
In my code, I am using ...
0
votes
1
answer
46
views
Is it possible to come up with distinct strings with identical hashcodes algorithmically?
In Java we know some examples of strings which have identical hash codes despite being distinct strings, such as Ea and FB both having a hash code of 2236.
Is there a way, algorithmically, to come up ...
0
votes
1
answer
154
views
Why does calling hashcode() change the hashcode value of my variable? [duplicate]
Could someone explain the following behavior for .hashcode().
When working with the two classes below I get different values for .hashcode() calls. Now I am just trying to understand the reason behind ...
1
vote
2
answers
108
views
Should hash code formulas change based on the variables ranges?
I have a basic class called Dice that represents groups of dice. The format I use for them is D&D's format of NdX. Where N is the number of dice and X is the number of sides each dice has. EG. 5d6 ...
2
votes
3
answers
173
views
Curious Java Hashcode Behaviour with Duplicate positive and negative doubles
I had a bit of a curious behaviour with negative and positive double value hashcodes I was not expecting. Essentially, if the same Double value appears twice in the hashcode function, if the sign of ...
1
vote
0
answers
26
views
Java Hashcode and equals are equals the object are not equals how come?
I have a custom key. However the test to make them equal is failing.
The hash and equals have been overriden
Can you please give me some clue?
@Getter
@Setter
public class CustomKey {
private int ...
1
vote
1
answer
75
views
What is the most efficient way to key a xyz pair in a C# dictionary?
I have a bunch of objects with xyz pairs (bytes) that I need to add to a dictionary. It's in the tens of thousands and I'm not sure what the most efficient way would be to go about it.
Would ...
-2
votes
1
answer
107
views
HashMap Key and Values, does i need to define equals and hashCode() all time? [duplicate]
I have a question about HashMap<Key,Values>.
Let's imagine this scenario:
I have a Person class:
Person a=new Person(int id, String fullName, int age)
I didn't define the equals and hashCode ...
2
votes
3
answers
352
views
.NET combine hash codes insensitive to order
I'm looking for an implementation of hash code to use alongside IReadOnlySet<T>.SetEquals.
.NET's HashCode type appears to be order sensitive, so it is not a good fit.
var random = new Random();
...
0
votes
0
answers
82
views
low collision hash function for unordered lists
Suppose I have a list of 64-bit integers $X = (x_1,x_2,\ldots,x_N)$.
I want to make a hash signature for $X$ with a very low collision rate, preferably one as low as the SHA functions.
The catch is ...
2
votes
1
answer
140
views
NullPointerException when trying to deserialize special object graph with Java 9 or later
I'm workig (as a part of a team) on an Enterprise Java application that has been in active development for 15+ years now. We are looking to build a REST API that would call some of the EJBs of the '...
-1
votes
1
answer
67
views
How to implement equals method for class contains another class in java
I want to compare StudentDTO class object.
StudentDTO s1 = new StudentDTO();
StudentDTO s2 = new StudentDTO();
s1.equals(s2)
I have Class StudentDTO contains AddressDTO class object as ...