java关于final的疑惑
public class H {public static void main(String []args) {
final H h =new H();
H g =new H();
}
}
有无final有什么区别?
@Test void test() { Info info=new Info(18,"张三",18); System.out.println("第一次info的值==="+info); System.out.println("第一次info的内存地址==="+info.hashCode()); info=new Info(); info.setId(20); info.setName("李四"); info.setAge(28); System.out.println("修改后info的值==="+info); System.out.println("修改后info的内存地址==="+info.hashCode()); } }
package java_demo; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import spring.model.Info; class javaTest { @Test void test() { final Info info=new Info(18,"张三",18); System.out.println("第一次info的值==="+info); System.out.println("第一次info的内存地址==="+info.hashCode()); info=new Info(); info.setId(20); info.setName("李四"); info.setAge(28); System.out.println("修改后info的值==="+info); System.out.println("修改后info的内存地址==="+info.hashCode()); } }