You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Weverton edited this page Sep 1, 2016
·
4 revisions
Uma das implementações corretas do padrão singleton:
// singleton classe
class SpeedSensor {
// construtor privado
private SpeedSensor(){}
// static inner class
private static class SpeedSensorHolder {
// membro static do tipo da outer class
public static SpeedSensor ss = new SpeedSensor();
}
// metodo static que retorna a instancia do tipo dessa classe
public static SpeedSensor getSpeedSensor() {
return SpeedSensorHolder.ss;
}
}