箭头运算符“ - >”在Java中做了什么?(What does the arrow operator, '->', do in Java?)
在通过一些代码搜索时,我遇到了箭头操作符,它究竟是做什么的? 我以为Java没有箭头操作符。
return (Collection<Car>) CollectionUtils.select(listOfCars, (arg0) -> { return Car.SEDAN == ((Car)arg0).getStyle(); });
详细信息 :Java 6,Apache Commons Collection,IntelliJ 12
更新/答案:事实证明,IntelliJ 12支持Java 8,它支持lambdas,并且是“折叠”谓词并将其显示为lambdas。 以下是“未折叠”代码。
return (Collection<Car>) CollectionUtils.select(listOfCars, new Predicate() { public boolean evaluate(Object arg0) { return Car.SEDAN == ((Car)arg0).getStyle(); } });
While hunting through some code I came across the arrow operator, what exactly does it do? I thought Java did not have an arrow operator.
return (Collection<Car>) CollectionUtils.select(listOfCars, (arg0) -> { return Car.SEDAN == ((Car)arg0).getStyle(); });
Details: Java 6, Apache Commons Collection, IntelliJ 12
Update/Answer: It turns out that IntelliJ 12 supports Java 8, which supports lambdas, and is "folding" Predicates and displaying them as lambdas. Below is the "un-folded" code.
return (Collection<Car>) CollectionUtils.select(listOfCars, new Predicate() { public boolean evaluate(Object arg0) { return Car.SEDAN == ((Car)arg0).getStyle(); } });
原文:https://stackoverflow.com/questions/15146052
更新时间:2024-03-02 22:03
最满意答案
Date.today.strftime "%b %d, '%y" Time.now.strftime "%I:%M%p"
Date.today.strftime "%b %d, '%y" Time.now.strftime "%I:%M%p"
相关问答
更多-
萧山劲松小学新伟业电脑培训中心人民路206号[2023-05-18]
22 -
没有必要那么做; 它可以在MySQL中完成。 LOAD DATA INFILE 'data.csv' INTO TABLE prices FIELDS TERMINATED BY ',' ENCLOSED BY '"' (partno, desc, @net, @gross, comment) SET net=REPLACE(@net, ',', '.'), gross=REPLACE(@gross, ',', '.'), There's no need for that; it can ...
-
将字符串“22/08/2013”转换为日期格式2013/08/22(Convert String “22/08/2013” to date format 2013/08/22)[2022-05-16]
您需要定义一个SimpleDateFormat ,它首先解析您的字符串并从中获取Date 。 然后将其转换为任何格式。 var s:String ="22/08/2013" var simpleDateFormat:SimpleDateFormat = new SimpleDateFormat("dd/mm/yyyy"); var date:Date = simpleDateFormat.parse(s); val ans = new SimpleDateFormat("yyyy/mm/dd") ... -
格式化代码以获取所有类型的日期。 你需要在参数中传递它的3件事是dateStr ,dateStr格式是strReadFormat ,你在输出中所需的fortmat是strWriteFormat 。 public String getFormattedDate(String dateStr, String strReadFormat, String strWriteFormat) { String formattedDate = dateStr; DateFormat readFormat ...
-
Date.today.strftime "%b %d, '%y" Time.now.strftime "%I:%M%p" Date.today.strftime "%b %d, '%y" Time.now.strftime "%I:%M%p"
-
有效的Ruby日期时间格式 Date.strptime("09-feb-73", "%d-%b-%y").strftime("%m/%d/%Y") 请注意, strptime是Rails的一部分。 这些是使用的相关格式: %b - 缩写的月份名称(``Jan'') %d - 每月的某一天(01..31) %m - 一年中的某个月(01..12) %y - 没有世纪的年份(00..99) %Y - 与世纪的年份 Valid Ruby datetime formats Date.strptime("09-fe ...
-
你可以使用at或crontab I think I figured out the problem - due to daylight savings time, incrementing 6-Nov-2011 by one day results in 6-Nov-2011 23:00:00 instead of 7-Nov-2011! Suppose I can put in an "if" for this special case.
-
为什么在使用专门为处理日期而设计的函数时使用substr()? $date = new DateTime('2012-03-19T22:10:56.000Z'); echo $date->format('r Y'); 看到它在行动 Why use substr() when you can use functions designed specifically for working with dates? $date = new DateTime('2012-03-19T22:10:56.000Z'); ...
-
这应该工作,我纠正了2个错误: 首先,格式应该是yyyy-MM-dd因为这是您输入的格式。 然后,你不能隐含地将java.util.Date为java.sql.Date ,你需要使用java.sql.Date构造函数和java.util.Date#getTime() 。 看这里 解 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); java.sql.Date SQLDate = new java.sql.Dat ...