无法使用add()添加jvmArgs,为什么? [英] Can't add jvmArgs using add(), why?

查看:73
本文介绍了无法使用add()添加jvmArgs,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释为什么第一个样本起作用而第二个样本却什么也没做?

Can anyone explain why the first sample working while the second does nothing?

test {
    jvmArgs '-Xdebug',
            '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=4000'
}

test {
    jvmArgs.add('-Xdebug')
    jvmArgs.add('-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=4000')
}

推荐答案

因为在第二个示例中

Because in the second example this method is invoked. You get the list, modify it but the changes are not reflected to settings - read only access. In the first example this method is invoked and arguments passed are set.

以下是说明,将返回列表的副本(出于安全性,安全性的考虑,可变类型应始终作为副本返回)

Here's the explanation, a copy of the list is returned (it's for safety, security reasons - mutable types should be always returned as a copy)

public List<String> getJvmArgs() {
   List<String> args = new ArrayList<String>();
   for (Object extraJvmArg : extraJvmArgs) {
      args.add(extraJvmArg.toString());
   }
   return args;
}

这篇关于无法使用add()添加jvmArgs,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆