【问题标题】:when NOT to use Pre compilation in scripting?什么时候不要在脚本中使用预编译?
【发布时间】:2018-03-08 17:46:50
【问题描述】:

我读到了Pre compilation scriptwhen you must compile script

我想知道是否存在预编译脚本会导致脚本失败或导致错误行为的情况?还是在运行脚本时预编译总是正确的方式?

是否有一个脚本会在预编译失败但没有它的情况下工作的选项?

任何解释将不胜感激。

【问题讨论】:

    标签: java groovy scripting jsr223


    【解决方案1】:

    我发现用于静态编译的 groovy disadvantages 主要是缺少动态特性/动态方法调度。

    我找到了一个用于动态方法调度的example

    class Categorizer {
    
     void accept(String s) { println "String: '$s'" }
     void accept(Number n) { println "Number: $n" }
     void accept(Object o) { println "Object: $o" }
    
     void accept(Object... objects) {
        objects.each {
          accept(it)
        }
      }
    }
    
    new Categorizer().accept(
      "a",
      "${'b'}",
      1,
      true,
      ["c", "d", 2] as Object[]
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      • 2012-05-18
      • 1970-01-01
      • 2011-12-31
      • 2013-04-23
      相关资源
      最近更新 更多