【问题标题】:Is it possible to implement the compare FI to compare two different type of objects?是否可以实现比较 FI 来比较两种不同类型的对象?
【发布时间】:2017-05-07 16:18:56
【问题描述】:
我正在研究如何使用 FI 和 lambda 表达式,我想知道是否可以比较两个不同类型的对象,例如 Integer 对象和 String 对象。有时,我看到它们可以互换使用,例如 Char 变成 Integer 或 CharSequence 变成 String。这让我想到比较它们,因为它们都来自 Object 超类。
谢谢。
【问题讨论】:
标签:
object
interface
functional-programming
compare
【解决方案1】:
我不完全清楚你在这里问什么。
但是,我猜你看到一个 char 被用来表示它的 Unicode 值时,它被与一个 Integer 进行比较(参见:this question)。
相反,String 和 CharSequence 之间的关系是实现接口的类的关系(查看this 了解更多信息)