Groovy'as'关键字来实现2+接口 [英] Groovy 'as' keyword to implement 2+ interfaces

查看:215
本文介绍了Groovy'as'关键字来实现2+接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个具有AdvancedTableFormat和WritableTableFormat接口的Glazed List。



我在这里阅读:
http://www.jroller.com/aalmiray/entry/glazedlists_groovy_not_your_regular



,对于一个接口,Groovy似乎可以使用as关键字:

 #return新的EventTableModel(linksList,[
#getColumnCount:{columnNames.size()},
#getColumnName:{index - > columnNames [index]},
#getColumnValue:{object,index - >
#object。$ {columnNames [index] .toLowerCase()}
#}] as TableFormat)

是否有可能为两个接口执行此操作?如果是这样怎么样?

谢谢!



Misha

解决方案

您可以创建一个新界面来扩展您感兴趣的两个界面。

  interface PersonalizedTableFormat extends AdvancedTableFormat,WriteableTableFormat {
}

您可以将对象返回新的界面。

 返回对象为PersonalizedTableFormat; 


I would like to implement a Glazed List that has both an AdvancedTableFormat and WritableTableFormat interface.

I am reading here: http://www.jroller.com/aalmiray/entry/glazedlists_groovy_not_your_regular

and for one interface it seems this is possible in Groovy with the "as" keyword:

# return new EventTableModel(linksList, [  
#       getColumnCount: {columnNames.size()},  
#       getColumnName: {index -> columnNames[index]},  
#       getColumnValue: {object, index ->  
#          object."${columnNames[index].toLowerCase()}"  
#       }] as TableFormat)

Is it somehow possible to do this for two interfaces? If so how?

Thank you!

Misha

解决方案

You can create a new interface that extends the two interfaces you are interested in.

interface PersonalizedTableFormat extends AdvancedTableFormat, WriteableTableFormat {
}

You can cast the object you return to the new interface.

return object as PersonalizedTableFormat;

这篇关于Groovy'as'关键字来实现2+接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆