Singleton classes, if properly implemented, do not need to be declared final in order to not be extended. Since all the constructors of the singleton class are private, you can't extend that class. In fact, singleton classes are effectively final.stackoverflow
giovedì, gennaio 26, 2017
Singleton are effectively final
giovedì, gennaio 12, 2017
DayLight change in Italy
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 org.enricogiurin.ocpjp.ch5; | |
import java.time.*; | |
/** | |
* Created by enrico on 11/19/16. | |
* ora legale | |
*/ | |
public class DayLight { | |
public static void main(String[] args) { | |
DayLight dayLight = new DayLight(); | |
dayLight.oraLegaleInItalia(); | |
} | |
public void oraLegaleInItalia() { | |
//26/3/2017 - 02:00 - entra ora legale | |
//29/10/2017 -03:00 - torna ora solare | |
LocalDate localDate = LocalDate.of(2017, Month.MARCH, 26); | |
LocalTime localTime = LocalTime.of(1, 30); | |
ZoneId defaultZoneId = ZoneId.systemDefault(); //Europe/Rome | |
ZonedDateTime zonedDateTime = ZonedDateTime.of(localDate, localTime, defaultZoneId); | |
//it is 1.30 and the GMT +1 | |
System.out.println(zonedDateTime); | |
zonedDateTime = zonedDateTime.plusHours(1); | |
//it is 3.30 and the GMT +2 | |
System.out.println(zonedDateTime); | |
//now let's go to october (torna ora solare) | |
localDate = LocalDate.of(2017, Month.OCTOBER, 29); | |
localTime = LocalTime.of(2, 30); //note the daylight starts at 3:00 | |
defaultZoneId = ZoneId.systemDefault(); //Europe/Rome | |
zonedDateTime = ZonedDateTime.of(localDate, localTime, defaultZoneId); | |
//it is 2.30 and the GMT +2 | |
System.out.println(zonedDateTime); | |
zonedDateTime = zonedDateTime.plusHours(1); | |
//it is 2.30 and the GMT +1 | |
System.out.println(zonedDateTime); | |
} | |
} |
Iscriviti a:
Post (Atom)