ich verstehe nicht warum pattern, date und temperature transient sein sollen. das datum ist serializable genau so wie String. wieso muss bei final ein transient gesetzt werden? sind alle primitiven typen nicht serializable ?
i dont get why pattern date and temperature need to be transient... the date is serializable like string? why is a final variable not deserializing meaning that all final variables should be transient. are all primitive types not serializable?
package de.codegym.task.task20.task2014;
import java.text.SimpleDateFormat;
import java.util.Date;
/*
Serializable Solution
*/
public class Solution {
public static void main(String[] args) {
System.out.println(new Solution(4));
}
private final String pattern = "dd MMMM yyyy, EEEE";
transient private Date currentDate;
private int temperature;
String string;
public Solution(int temperature) {
this.currentDate = new Date();
this.temperature = temperature;
string = "Heute ist %s und die aktuelle Temperatur beträgt %s C";
SimpleDateFormat format = new SimpleDateFormat(pattern);
this.string = String.format(string, format.format(currentDate), temperature);
}
@Override
public String toString() {
return this.string;
}
}