在Java程序中,我有一个我想根据特定属性过滤的bean列表.
例如,假设我有一个Person列表,一个JavaBean,其中Person有许多属性,其中包括'name'.
我还有一个名单.
现在我想找到名字列在名单中的所有人.
使用Google Guava执行此过滤器的最佳方法是什么?
到目前为止,我已经考虑过将Guava与Apache beanutils相结合,但这似乎并不优雅.
我还在这里找到了一个反射扩展库:http://code.google.com/p/guava-reflection/,但我不确定如何使用它(这里有很少的文档).
有什么想法吗?
ps你能告诉我真的很想念Python列表理解吗?
我不明白我在下面的代码(Scala 2.9)中看到的明显的矛盾行为:
class Pimp1(val x : Double) {
def pluss(that : Pimp1) = x + that.x
def <(that : Pimp1) = x < that.x
}
object Pimp1 {
implicit def d2pimp(d : Double) = new Pimp1(d)
implicit def d2pimp(od : Option[Double]) = new Pimp1(od.get)
}
object Scratch2 extends App {
import Pimp1._
5.0.pluss(Some(5.0))
5.0 < Some(5.0)
}
Run Code Online (Sandbox Code Playgroud)
行'5.0.pluss(Some(5.0))'编译,但它后面的行不会编译,并显示以下错误消息:
重载方法值<with alternatives:(x:Double)Boolean(x:Float)Boolean(x:Long)Boolean(x:Int)Boolean(x:Char)Boolean(x:Short)Boolean(x:Byte)布尔值不能适用于(某些[双])
如果我将显式的<运算符添加到Pimp类中,该类采用Option [Double]:
def <(that : Option[Double]) = x < that.get
Run Code Online (Sandbox Code Playgroud)
一切都很好.
现在,我理解Scala隐式转换规则的方式,这很有道理:
这就是我期望事情发挥作用的方式. …