Created
May 16, 2019 17:26
-
-
Save BoneFlute/6c9f56a6b4c164b2fc2f246662daa7a8 to your computer and use it in GitHub Desktop.
Ekvivalence a identita, java versus python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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