标签:方便 initial vat style public test rom tty ESS
看到这样一种用法,很方便
request.setRequestHead(new RequestHeadType() {{ setRequestor("Online"); setRequestType("Hotel.Order.ProcessService.SelfService.ModifyInvoice"); setClientAppID("100002669"); setTimeStamp(LocalDateTime.now().toString()); setRequestID(UUID.randomUUID().toString()); setServerFrom("test"); }});
刚开始两个{{}}没有看懂
与下面的情况很类似:
public class test11 { public static void main(String[] args) { new test11("321"); } static { System.out.println("test11.static initializer"); } { setName("123"); System.out.println(this.name); } public test11(String name) { this.name = name; System.out.println("test11." + this.name); } private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
输出结果:
test11.static initializer 123 test11.321
第一个大括号是方法的重写
第二个大括号是重写的代码块,比构造方法还先执行,并且可调用类的set方法
标签:方便 initial vat style public test rom tty ESS
原文地址:https://www.cnblogs.com/twoheads/p/9989215.html