简体   繁体   English

参数调用内的花括号。 >>这是什么意思? |春季3和GWT

[英]curly braces inside parameter call. >> what does it mean? | Spring 3 and GWT

question

When the code segment "new TextColumn(){...}, "MyObjectId");" 当代码段“new TextColumn(){...},”MyObjectId“);” executes then what does the code inside the outermost of pair curly braces represent? 然后执行对花括号中最外面的代码代表什么? Does it represent an anonymous inner class instance of the TextColumn object? 它是否代表TextColumn对象的匿名内部类实例? Does it represent the definition of the TextColumn object? 它是否代表TextColumn对象的定义?

code

table.addColumn(new TextColumn<MyObjectProxy>() {
    Renderer<Integer> renderer = new AbstractRenderer<Integer>() {
        public String render(Integer obj) {
            return obj == null ? "" : String.valueOf(obj);
        }
    };
    @Override
    public String getValue(MyObjectProxy object) {
        return renderer.render(object.getMyObjectId());
    }
}, "MyObjectId");

if you are wondering the TextColumn is from the com.google.gwt.user.cellview.client.TextColumn package. 如果您想知道TextColumn来自com.google.gwt.user.cellview.client.TextColumn包。

That's an anonymous inner class that extends TextColumn<MyObjectProxy> . 这是一个扩展TextColumn<MyObjectProxy>的匿名内部类。 In it, it has a field named renderer of type Renderer<Integer> that is initialized with an instance of an anonymous inner class that extends AbstractRenderer<Integer> . 在其中,它有一个名为renderer类型为Renderer<Integer>的字段,该字段使用扩展AbstractRenderer<Integer>的匿名内部类的实例进行初始化。 There is also an override of method getValue below that. 在下面还有一个方法getValue的覆盖。

It simply defines an anonym class and creates an instance of it. 它只是定义一个匿名类并创建它的实例。 This instance is passed as parameter to the method table.addColumn . 此实例作为参数传递给方法table.addColumn

Yes, it's an anonymous class, corresponding to the TextColumn Object. 是的,它是一个匿名类,对应于TextColumn对象。

The getValue() method is overriden. getValue()方法被覆盖。

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

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