简体   繁体   English

在Java中使用Groovy PowerAssert

[英]Using Groovy PowerAssert in Java

I am using Java EE with Maven. 我正在使用Maven的Java EE。 For readability and easy checks, I want to use Groovy's PowerAssert in production code. 为了便于阅读和检查,我想在生产代码中使用Groovy的PowerAssert

Is there a way of doing this in standard Java classes? 有没有办法在标准Java类中执行此操作?

I tried adding the 'groovy-all' package as Maven dependency, but the following code fails. 我尝试将'groovy-all'包添加为Maven依赖项,但以下代码失败。 What should I import? 我应该导入什么?

public static void main(String[] args) {
  assert (2 + 2 == 5, "Surprise: this assertion failed!");
}

I'm assuming you mean the code fails to compile, but correct me if I'm wrong. 我假设你的意思是代码无法编译,但如果我错了,请纠正我。 You're not going to be able to use Groovy-only syntax in your Java classes, I'm afraid. 我担心你不能在Java类中使用仅Groovy语法。 The guts of groovy for this functionality seem interwoven with Groovy compilation, if a quick look is correct, so I don't think it's really hackable for your java code. 对于这个功能而言,groovy的内容似乎与Groovy编译交织在一起,如果快速查看是正确的,那么我认为它对你的java代码来说真的不可思议。 For areas of code where you want groovy functionality, perhaps you can embed scripts. 对于需要常规功能的代码区域,也许您可​​以嵌入脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM