Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@ -2,18 +2,21 @@ package com.iluwatar.value.object;
|
||||
|
||||
/**
|
||||
* App Class.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
/**
|
||||
* main method.
|
||||
* A Value Object must check equality with equals() not == <br>
|
||||
* This practice creates three HeroStats(Value object) and checks equality between those.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
HeroStat statA = HeroStat.valueOf(10, 5, 0);
|
||||
HeroStat statB = HeroStat.valueOf(5, 1, 8);
|
||||
HeroStat statB = HeroStat.valueOf(10, 5, 0);
|
||||
HeroStat statC = HeroStat.valueOf(5, 1, 8);
|
||||
|
||||
System.out.println(statA.toString());
|
||||
// When using Value Objects do not use ==, only compare using equals().
|
||||
System.out.println("is statA and statB equal : " + statA.equals(statB));
|
||||
|
||||
System.out.println("Is statA and statB equal : " + statA.equals(statB));
|
||||
System.out.println("Is statA and statC equal : " + statA.equals(statC));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user