简体   繁体   中英

Using Groovy PowerAssert in Java

I am using Java EE with Maven. For readability and easy checks, I want to use Groovy's PowerAssert in production code.

Is there a way of doing this in standard Java classes?

I tried adding the 'groovy-all' package as Maven dependency, but the following code fails. 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. 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. For areas of code where you want groovy functionality, perhaps you can embed scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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