MR-LI_20200902-李伟江
问题
1. java.util.Date ——> java.Time.LocalDateTime 的过程理解
**5、创建Date类型的实例 **
4、要获得Instant类型的实例。
Date类有toInstant方法,返回值是Instant实例。
public Instant toInstant()
Date——>Instant
3、要获得ZoneId的实例,可以通过ZoneId提供的类方法。
桥梁。public static ZoneId systemDefault()
2、要获取ZonedDateTime类型的实例,可以通过Instant类型的实例调用atZone方法
atZone该方法的返回值是ZonedDateTime类型,且参数是ZoneId类型的实例。
public ZonedDateTime atZone(ZoneId zone)
Instant——>ZonedDateTime
1、因为ZonedDateTime的实例可以通过toLocalDateTime方法返回LocalDateTime类型的实例
ZonedDateTime内部有LocalDateTime类型的字段
ZonedDateTime——>LocalDateTime
public static void main(String[] args) {
Date date = new Date();
Instant instant = date.toInstant();
ZoneId zone = ZoneId.systemDefault();
ZonedDateTime zoneDateTime = instant.atZone( zone );
LocalDateTime ldt = zoneDateTime.toLocalDateTime();
}
2.
public class Father {
public String name;
public Father() {
System.out.println( this.name );
}
public void show() {
// System.out.println( this.name ); 这是后面加上去的,加上这条语句会输出name的值
System.out.println("this is show");
}
}
public class Son extends Father {
public Son() {
super.name = "a";
super.show();
}
public static void main(String[] args) {
Son son = new Son();
}
}
输出 null
this is show
刚开始以为super.name没有为父类中的字段赋值,因为父类构造执行的时候没有输出。后来在下面的show方法中加上输出的时候,显示已经赋值。
但是为什么父类构造为什么不会执行输出语句
补充
昨晚睡不着,想到的解释应该是构造方法只是为了创建对象,除了创建对象啥也不干。所以构造执行的时候,不会执行和创建对象不相干的语句。
然后昨晚宿舍又讨论到这个问题
StringBuffer s1 = new StringBuffer("123");
StringBuffer s2 = new StringBuffer("123");
String s = s1 + s2;
System.out.println( s );
第三行会出现编译错误,为什么StringBuff的实例对象是不可相加?
eclipse给出的解释是
The operator + is undefined for the argument type(s) java.lang.StringBuffer, java.lang.StringBuffer
这个 "+" 在StringBuffer类里面应该没有做相关处理,而String类应该做了处理。到底是怎么处理的就不懂了。
吐槽
绕着绕着就把自己绕进去了。觉得学的越多,自己就知道的越少。
近期评论