你打电话的时候 :
Run Code Online (Sandbox Code Playgroud)Object isThreadSafe = scriptEngine.getFactory().getParameter("THREADING");
它MULTITHREADED按以下方式返回:
但目前尚不清楚这是什么影响.
这是否意味着:
如果答案可以用一些代码说明,那将是很好的.
我正在阅读Haskell编程书籍并在GHCi解释器中测试提供的示例.事实证明,IntGHCi和Hugs解释器中的类型行为存在差异.根据"Haskel编程"第3章,2^31 :: Int应该超出Int类型范围.同时,在GHCi翻译中,我得到:
Prelude> 2^31 :: Int
2147483648
Run Code Online (Sandbox Code Playgroud)
而在Hugs中它的表现就像书中说的那样:
Hugs> 2^31 :: Int
-2147483648
Run Code Online (Sandbox Code Playgroud)
在GHCi中我甚至可以检查结果是否是类型 Int
Prelude> let x = 2^31 :: Int
Prelude> :type x
x :: Int
Prelude> x
2147483648
Run Code Online (Sandbox Code Playgroud)
描述差异的来源是什么?我应该从Hugs中的书中运行示例还是使用GHCi,这似乎是学习Haskell的推荐选择?我将非常感谢你的帮助.
我已经开始使用Java 8并尝试将我的代码中的一些循环和旧语法转换为lambdas和流.
因此,例如,我正在尝试将此转换为for循环以转换为流,但我没有做到正确:
List<String> list = new ArrayList<>();
if (!oldList.isEmpty()) {// old is a List<String>
Iterator<String> itr = oldList.iterator();
while (itr.hasNext()) {
String line = (String) itr.next();
for (Map.Entry<String, String> entry : map.entrySet()) {
if (line.startsWith(entry.getKey())) {
String newline = line.replace(entry.getKey(),entry.getValue());
list.add(newline);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以将上面的示例转换为单个流,其中for循环内部有一个while循环.
我正在使用PropertyUtils.setSimpleProperty来动态调用我的setter方法,但是由于某些原因,我一直在出错。需要您的协助以找出根本原因。这是我的代码:
class FileDt {
String reportName=null;
String reportLocation=null;
public String getReportName() {
return reportName;
}
public void setReportName(String reportName) {
this.reportName = reportName;
}
public String getReportLocation() {
return reportLocation;
}
public void setReportLocation(String reportLocation) {
this.reportLocation = reportLocation;
}
}
class Foo {
public static void main (String... args) {
FileDt dt = newFileDt();
// #1
PropertyUtilsBean.setSimpleProperty(dt, "reportName", "abc.html");
// #2
PropertyUtilsBean.setSimpleProperty(dt, "reportLocation", "c://");
}
}
Run Code Online (Sandbox Code Playgroud)
这两种方法都抛出异常
由以下原因引起:java.lang.NoSuchMethodException:属性'reportName'在org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2096)的类'FileDt'中没有setter方法
由以下原因引起:java.lang.NoSuchMethodException:属性'reportLocation'在org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2096)的类'FileDt'中没有setter方法
我不明白断言在@PactVerification. 对我来说,这更像是一种复杂的说法1 == 1。例如:
import static org.assertj.core.api.Assertions.assertThat;
public class PactConsumerDrivenContractUnitTest {
@Rule
public PactProviderRuleMk2 mockProvider
= new PactProviderRuleMk2("test_provider", "localhost", 8080, this);
@Pact(consumer = "test_consumer")
public RequestResponsePact createPact(PactDslWithProvider builder) {
return builder
.given("test GET ")
.uponReceiving("GET REQUEST")
.path("/")
.method("GET")
.willRespondWith()
.body("{\"condition\": true, \"name\": \"tom\"}")
}
@Test
@PactVerification()
public void givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody() {
//when
ResponseEntity<String> response
= new RestTemplate().getForEntity(mockProvider.getUrl(), String.class);
//then
assertThat(response.getBody()).contains("condition", "true", "name", "tom");
}
}
Run Code Online (Sandbox Code Playgroud)
所以首先在“createPact”中我们声明
body("{\"condition\": true, \"name\": \"tom\"}")
Run Code Online (Sandbox Code Playgroud)
然后在givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody注释中@PactVerification我们这样做
assertThat(response.getBody()).contains("condition", "true", …Run Code Online (Sandbox Code Playgroud) I am not sure this has been answered earlier or not. Can anyone please tell me what is the problem with third groupBy which I've written ? Why it can not infer ?
class TestGroupBy
{
enum LifeCycle {
ANNUAL, PERENNIAL
}
private String name;
private LifeCycle lifeCycle;
TestGroupBy(String name, LifeCycle lifeCycle) {
this.name = name;
this.lifeCycle = lifeCycle;
}
LifeCycle getLifeCycle() {
return this.lifeCycle;
}
static EnumMap mySupplier() {
return new EnumMap(TestGroupBy.class);
}
public static void main(String[] args) { …Run Code Online (Sandbox Code Playgroud) 我需要在Jenkins中创建一个Groovy post构建脚本,我需要在不使用任何第三方库的情况下发出请求,因为这些库不能从Jenkins引用.
我试过这样的事情:
def connection = new URL( "https://query.yahooapis.com/v1/public/yql?q=" +
URLEncoder.encode(
"select wind from weather.forecast where woeid in " + "(select woeid from geo.places(1) where text='chicago, il')",
'UTF-8' ) )
.openConnection() as HttpURLConnection
// set some headers
connection.setRequestProperty( 'User-Agent', 'groovy-2.4.4' )
connection.setRequestProperty( 'Accept', 'application/json' )
// get the response code - automatically sends the request
println connection.responseCode + ": " + connection.inputStream.text
Run Code Online (Sandbox Code Playgroud)
但我还需要在POST请求中传递JSON,我不知道如何做到这一点.任何建议表示赞赏.
我刚刚开始练习 Groovy,我有一个与地图和 IDEA IDE 相关的问题。
Integer当我尝试用作地图的密钥时,为什么 IDEA 会显示以下通知?这个简单的 Groovy 脚本运行良好并打印正确的结果。
list = [4, 7, 3, 7, 7, 1, 4, 2, 4, 2, 7, 5]
map = [:]
list.each {
t = map[(it)]
map[(it)] = t != null ? t + 1 : 1
}
map.each {key, value -> if (value == 1) println key}
Run Code Online (Sandbox Code Playgroud) 我在执行以下 Groovy 脚本片段时遇到问题。
GroovyShell sh = new GroovyShell();
sh.evaluate("\"abcd\".length() >= .34");
Run Code Online (Sandbox Code Playgroud)
我收到以下异常。下面提到了整个堆栈跟踪。
Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: unexpected token: >= @ line 1, column 17.
"abcd".length() >= .34d
Run Code Online (Sandbox Code Playgroud)
如果我更改.34为0.34,它就有效。但是,由于某些限制,我无法更改脚本内容。任何克服的帮助将不胜感激。
我遇到以下异常
Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: unexpected token: >= @ line 1, column 17.
"abcd".length() >= .34d
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:144)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:110)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:168)
at …Run Code Online (Sandbox Code Playgroud) 我在Jenkinsfile中发现了Groovy代码的奇怪问题:
@NonCPS
def test() {
println "Start"
sleep(10)
println "Stop"
}
Run Code Online (Sandbox Code Playgroud)
事实是,睡眠10秒钟之后,代码就再也无法进入了println "Stop"。
看来,睡眠会在10秒后返回并运行下一个管道步骤。
输出只是:
[Pipieline] echo
Start
[Pipeline] sleep
Sleeping for 10 sec
[Pipeline] }
... next pipeline steps
Run Code Online (Sandbox Code Playgroud)
有人遇到过同样的问题吗?