Groovy'as'关键字来实现2+接口 [英] Groovy 'as' keyword to implement 2+ interfaces
问题描述
我想实现一个具有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屋!