小编Iva*_*nuk的帖子

groovy.lang.Binding difference between property and variable

Couldn't really figure out/find what a difference between thouse two

import groovy.lang.Binding;
import groovy.lang.GroovyShell;

class Scratch {
    public static void main(String[] args) {
        Binding binding = new Binding();
        Integer p = 1,
                v = 1;
        binding.setProperty("p", p);
        binding.setVariable("v", v);

        GroovyShell shell = new GroovyShell(binding);
        shell.evaluate("p++;v++;");
        System.out.println(String.format("BINDING Property = %s, Variable = %s", binding.getProperty("p"), binding.getVariable("v")));
        System.out.println(String.format("JAVA Property = %s, Variable = %s", p, v));
    }
}
Run Code Online (Sandbox Code Playgroud)

Output is:

BINDING Property = 2, Variable = 2
JAVA Property = 1, Variable = …
Run Code Online (Sandbox Code Playgroud)

java groovy

6
推荐指数
1
解决办法
3682
查看次数

标签 统计

groovy ×1

java ×1