[英]How to make a template for sysout the multi-localVal
for Example... ` 例如...
Object o1 = new Object();
Object o2 = new Object();
Object o3 = new Object();
` `
I want to select these sentence and ALT + SHITFT + Z : sysout the localVal to Test like this: ` 我想选择这些句子以及ALT + SHITFT + Z:sysout localVal进行测试,如下所示:
System.out.println(o1);
System.out.println(o2);
System.out.println(o3);
` how can i write such a template? `我怎么写这样的模板? Thx!
谢谢!
You can add the objects to a list and then print them all. 您可以将对象添加到列表中,然后全部打印。
This is very simple, hope it can help you some. 这很简单,希望对您有所帮助。
public void print(List<Object> objectList)
{
for(Object obj : objectList)
{
System.out.println(obj);
}
}
Another way you can implement it by using variable parameter 您可以通过使用可变参数来实现的另一种方式
code sample is as follows: 代码示例如下:
public void print1(Object ... objectList)
{
for(Object obj: objectList)
{
System.out.println(obj);
}
}
Using variable parameters, you can print objects like follows: 使用可变参数,可以打印如下对象:
Test t = new Test();
Object o1 = new Object();
Object o2 = new Object();
Object o3 = new Object();
t.print1(o1);
t.print1(o1,o2);
t.print1(o1,o2,o3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.