gpt4 book ai didi

java - 仅键入接口(interface)方法

转载 作者:行者123 更新时间:2023-12-01 23:37:06 24 4
gpt4 key购买 nike

我有这个界面

/**
* 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;
}

在实现此接口(interface)的类中是否有某种方式我可以将 T 键入特定的内容,我想确保 T 实现另一个接口(interface)?

最佳答案

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

为什么 IExportableColumn<T,?,?> 中有 2 个无界类型参数?当我在应用程序代码中看到这一点时,我总是感觉自己错过了一些东西。

您还可以使整个界面参数化,但从我看来,参数的数量需要相当大。至少 3 个。

关于java - 仅键入接口(interface)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18516172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com