2013-08-29 66 views
0

我有這個接口只有接口方法是鍵入

/** 
* Exports data provided by a {@link IDataProvider} as described by {@link IExportableColumn}s. This interface is used by 
* {@link ExportToolbar} to provide the export functionality. 
* 
* @author Jesse Long 
* @see ExportToolbar 
* @see IExportableColumn 
*/ 
public interface IDataExporter 
    extends IClusterable 
{ 
    ... 
    /** 
    * Exports the data provided by the {@link IDataProvider} to the {@link OutputStream}. 
    * 
    * @param <T> 
    *  The type of each row of data provided by the {@link IDataProvider}. 
    * @param dataProvider 
    *  The {@link IDataProvider} from which to retrieve the data. 
    * @param columns 
    *  The {@link IExportableColumn} to use to describe the data. 
    * @param outputStream 
    *  The {@link OutputStream} to which to write the exported data. 
    * @throws IOException If an error occurs. 
    */ 
    <T> void exportData(IDataProvider<T> dataProvider, List<IExportableColumn<T, ?, ?>> columns, OutputStream outputStream) 
     throws IOException; 
} 

是否有某種方式實現了這個接口,我可以T類型具體的東西類,我想確保牛逼實現另一個接口?

+0

'' –

+1

' void exportData(...)'? –

+1

似乎在接口名稱前面對'I'有很多仇恨,但是我發現它更容易挑選出它是一個快速接口,我知道你可以在日食中使用它們的類型來裝飾類,它不是一個可怕的慣例(儘管從C#中借用) – reevesy

回答

1

如果你總是想迫使T實現一些接口,只需使用

<T extends Thing> void exportData(. . .) 

如果你想限制T只有在實現類,可以使整個界面通用的(而不是隻是方法)。這可能是一個好主意,反正:

/** 
* Exports data provided by a {@link IDataProvider} as described by {@link IExportableColumn}s. This interface is used by 
* {@link ExportToolbar} to provide the export functionality. 
* @param <T> 
*  The type of each row of data provided by the {@link IDataProvider}. 
* 
* @author Jesse Long 
* @see ExportToolbar 
* @see IExportableColumn 
*/ 

public interface<T> IDataExporter extends IClusterable 
{ 
    ... 
    /** 
    * Exports the data provided by the {@link IDataProvider} to the {@link OutputStream}. 
    * 
    * @param dataProvider 
    *  The {@link IDataProvider} from which to retrieve the data. 
    * @param columns 
    *  The {@link IExportableColumn} to use to describe the data. 
    * @param outputStream 
    *  The {@link OutputStream} to which to write the exported data. 
    * @throws IOException If an error occurs. 
    */ 
    void exportData(IDataProvider<T> dataProvider, List<IExportableColumn<T, ?, ?>> columns, OutputStream outputStream) 
     throws IOException; 
} 

然後你就可以在綁定實現類聲明T

public class MyClass implements IDataExporter<MyRowType> { . . . } 
+0

org.apache.wicket.extensions.markup.html.repeater.data.table.export接口來自一個包,所以我不能在不復制大量代碼的情況下更改它。 –

2
<T extends MyRequisiteType> void exportData(IDataProvider<T> dataProvider, List<IExportableColumn<T,?,?>> columns, OutputStream outputStream) throws IOException; 

爲什麼2個無限類型IExportableColumn<T,?,?>參數?當我在應用程序代碼中看到這一點時,我總是有我失去一些東西的感覺。

您還可以使整個界面參數化,但從我所看到的參數數量需要非常大。 3,至少。