Skip to content

Commit e380d88

Browse files
committed
playing with hashCode() and assertions in main() method
1 parent a60efef commit e380d88

File tree

1 file changed

+36
-1
lines changed
  • src/main/java/com/epam/izh/rd/online

1 file changed

+36
-1
lines changed

src/main/java/com/epam/izh/rd/online/Main.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.epam.izh.rd.online;
22

33
import com.epam.izh.rd.online.entity.Author;
4+
import org.springframework.util.Assert;
5+
import org.springframework.util.SocketUtils;
46

57
public class Main {
68

@@ -13,11 +15,44 @@ public static void main(String[] args) {
1315
author1.setName("Yaroslav");
1416
author1.setCountry("Russia");
1517

18+
class FreakAuthor extends Author {
19+
public FreakAuthor(String name) {
20+
this.setName(name);
21+
}
22+
23+
@Override
24+
public int hashCode() {
25+
return Object.class.hashCode();
26+
}
27+
28+
}
29+
30+
FreakAuthor freak = new FreakAuthor("John");
31+
1632
System.out.println(author1.toString());
17-
System.out.println("\nHash code is " + author1.hashCode());
33+
System.out.println("\nHash code1 for author " + author1.getName() + " is " + author1.hashCode());
34+
System.out.println("Hash code2 for author " + author1.getName() + " is " + author1.hashCode());
35+
System.out.println("Hash code3 for author " + author1.getName() + " is " + author1.hashCode());
36+
37+
System.out.println("\nHash code1 for author " + freak.getName() + " is " + freak.hashCode());
38+
System.out.println("Hash code2 for author " + freak.getName() + " is " + freak.hashCode());
39+
System.out.println("Hash code3 for author " + freak.getName() + " is " + freak.hashCode());
1840

1941
}/* END OF DEBUGGING CLASS Author */
2042

43+
44+
{/* SECTION FOR PLAYING WITH ASSERTIONS */
45+
46+
try {
47+
Assert.isTrue(1 == 2, "What? 1 == 2? That's not true!!!");
48+
} /*catch ( IllegalArgumentException e ) {
49+
System.out.println("What was that?!");
50+
}*/ catch ( Exception e ) {
51+
System.out.println("\nIt was just an exception. Don't worry, be happy.\n");
52+
}
53+
54+
}/* END OF DEBUGGING ASSERTIONS */
55+
2156
}
2257

2358
}

0 commit comments

Comments
 (0)