Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中类似Kotlin的选择器_Java_Kotlin_Collections_Iterable - Fatal编程技术网

Java中类似Kotlin的选择器

Java中类似Kotlin的选择器,java,kotlin,collections,iterable,Java,Kotlin,Collections,Iterable,我在Kotlin中有这段代码,如何用Java编写 typealias ResolutionSelector = Iterable<Resolution>.() -> Resolution? /** * @return Selector function which always provides the biggest resolution. */ fun highestResolution(): ResolutionSelector = { maxBy(Resoluti

我在Kotlin中有这段代码,如何用Java编写

typealias ResolutionSelector = Iterable<Resolution>.() -> Resolution?

/**
 * @return Selector function which always provides the biggest resolution.
 */
fun highestResolution(): ResolutionSelector = { maxBy(Resolution::area) }
typealias ResolutionSelector=Iterable.(->分辨率?
/**
*@return选择器函数,始终提供最大分辨率。
*/
fun highestResolution():ResolutionSelector={maxBy(Resolution::area)}

很遗憾,Java没有类型别名。
我想你能得到的最好的是

resolutions.stream()
           .max(Comparator.comparingInt(Resolution::getArea));


Stream#max
接受
比较器为什么要这样做?向列表中添加自定义选择器。@AVEbrahimi我对Kotlin有点不了解,你能用文字描述一下吗?它有什么作用?
final Comparator<Resolution> resolutionComparator = (r1, r2) -> /* Comparison logic */;