简体   繁体   English

如何创建仅接受实现Iterable的元素的方法

[英]How to Create a Method that only accepts elements that implement Iterable

I want to write a function printAll(), which accepts only those elements that implement that implement Iterable so that I can iterate over them and print the elements. 我想编写一个函数printAll(),该函数仅接受那些实现了Iterable的元素,以便我可以对其进行迭代并打印这些元素。 How do I do that? 我怎么做?

public static void printAll(final Iterable<?> toIterate)

暂无
暂无

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

相关问题 如何在泛型类中实现Iterable &lt;&gt;方法 - How to implement the Iterable<> method in a generic class 如何在Java中创建一个通用方法,其中参数化类型之一必须实现Iterable? - How do you create a generic method in Java where one of the parameterized types must implement Iterable? 如何在Java中使用Iterable元素创建数组? - How to create an array with Iterable elements in Java? 如何创建一个在Java中接受回调函数的方法? - How to create a method that accepts a callback function in java? 创建一个方法,该方法接受一个整数数组,该整数数组填充元素之间缺少的数字 - create a method that accepts an integer array that fills in the missing number between the elements 如何在Java中使用泛型来创建一个泛型接口,该接口定义仅接受实现作为参数的方法? - How would I use generics in Java to create a generic interface that defines a method that only accepts the implementation as a parameter? 如何创建一个只接受泛型参数而不接受原始类型参数的泛型方法? - How to create a generic method that accepts only generic parameters and not raw type parameters? 如何强制子类以实现接受某种类型的方法 - How to enforce subclasses to implement a method which accepts a certain type 创建仅接受非抽象 Class 类型的 java 方法 - Create java method that only accepts non-abstract Class types 如何实现仅接受可比较对象的列表 Class - How to implement a List Class that only accepts Comparable Objects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM