Hello mates,
Why we should check object == null, and why OurPresident.class is argument in synchronized block. What means Class.class <= this small class after dot.
I admit I haven't read all the CG material yet maybe there explained?
static {
synchronized (OurPresident.class) {
if (president == null) {
president = new OurPresident();
}
}
}
package pl.codegym.task.task17.task1706;
/*
Zsynchronizowany prezydent
*/
public class Solution {
public static void main(String[] args) {
OurPresident expectedPresident = OurPresident.getOurPresident();
OurPresident ourPresident = OurPresident.getOurPresident();
System.out.println(expectedPresident == ourPresident );
}
}