Skip to content

Instantly share code, notes, and snippets.

@BoneFlute
Created May 16, 2019 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BoneFlute/6c9f56a6b4c164b2fc2f246662daa7a8 to your computer and use it in GitHub Desktop.
Save BoneFlute/6c9f56a6b4c164b2fc2f246662daa7a8 to your computer and use it in GitHub Desktop.
Ekvivalence a identita, java versus python
package name.boneflute.kata;
public class Main {
public static void main(String[] args)
{
int x = 1024;
int y = 1024;
Cislo a = new Cislo(1024);
Cislo b = new Cislo(1024);
System.out.println(a == b); // false
System.out.println(a.equals(b)); // true
System.out.println(x == y); // true
//System.out.println(x.equals(y));
}
public static class Cislo
{
private int value = 0;
public Cislo(int v) {
super();
value = v;
}
@Override
public int hashCode()
{
int hash = 7;
hash = 37 * hash + this.value;
return hash;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Cislo other = (Cislo) obj;
if (this.value != other.value) {
return false;
}
return true;
}
}
}
class Integer:
def __init__(self, value):
self.value = value
def __eq__(self, other):
return self.value == other.value
if __name__ == "__main__":
a = Integer(1024)
b = Integer(1024)
print (a == b) # True
print (a is b) # False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment