Jukka Siivonen
10/18/2018, 11:57 AMfun localDateFormatter(): Formatter<LocalDate> {
return object : Formatter<LocalDate> {
override fun parse(text: String, locale: Locale): LocalDate {
return LocalDate.parse(text, DateTimeFormatter.ISO_DATE)
}
override fun print(obj: LocalDate, locale: Locale): String {
return DateTimeFormatter.ISO_DATE.format(obj)
}
}
}
override fun parse(text: String, locale: Locale): LocalDate? {
it gives me error Return type is LocalDate? which is not a subtype of overriddenNikky
10/18/2018, 12:21 PM?: defaultDate
Jukka Siivonen
10/18/2018, 12:24 PMoverride fun parse(text: String, locale: Locale): LocalDate? {
does not compileReturn type is LocalDate? which is not a subtype of overridden
Nikky
10/18/2018, 12:25 PMFormatter<LocalDate>
with that signature you would need Formatter<LocalDate?>
Jukka Siivonen
10/18/2018, 12:25 PMNikky
10/18/2018, 12:26 PMJukka Siivonen
10/18/2018, 12:27 PMNikky
10/18/2018, 12:27 PMJukka Siivonen
10/18/2018, 12:27 PMNikky
10/18/2018, 12:29 PMJukka Siivonen
10/18/2018, 12:30 PM@Bean
fun localDateFormatter(): Formatter<LocalDate?> {
return object : Formatter<LocalDate?> {
override fun parse(text: String, locale: Locale): LocalDate? {
return null
}
override fun print(obj: LocalDate, locale: Locale): String {
return DateTimeFormatter.ISO_DATE.format(obj)
}
}
}
Nikky
10/18/2018, 12:31 PMJukka Siivonen
10/18/2018, 12:31 PMNikky
10/18/2018, 12:32 PMJukka Siivonen
10/18/2018, 12:33 PMpublic interface Formatter<T> extends Printer<T>, Parser<T> {
}
@FunctionalInterface
public interface Printer<T> {
/**
* Print the object of type T for display.
* @param object the instance to print
* @param locale the current user locale
* @return the printed text string
*/
String print(T object, Locale locale);
}
@FunctionalInterface
public interface Parser<T> {
/**
* Parse a text String to produce a T.
* @param text the text string
* @param locale the current user locale
* @return an instance of T
* @throws ParseException when a parse exception occurs in a java.text parsing library
* @throws IllegalArgumentException when a parse exception occurs
*/
T parse(String text, Locale locale) throws ParseException;
}
Nikky
10/18/2018, 12:33 PMJukka Siivonen
10/18/2018, 12:34 PMNikky
10/18/2018, 12:37 PM