要检测日期,2015-10-11 是不是YYYY-MM-DD的格式。 if (!startDate.matches("\d{4}-\d{2}-\d{2}")) { throw new Exception("ERROR: startDate " + startDate + " is invalid."); } reviewer说,Please compile the pattern + matcher, and use the matcher to match the dates. 我问,值得么? 他说。In terms of performance, yes. 这个真的很大的performance 的关系么? 还有,return new X>(new Y (Y) 非要分段写, 3行。 说是Readability. 这算鸡蛋里面挑骨头么? 更新: 3楼之后。 http://stackoverflow.com/questions/2149680/regex-date-format-va 这个检测我是看这个的。 第2条, 我看code里面很多都是如此写的。 不用第二次的local variable就省在new里 面不可以么?
【在 u***8 的大作中提到】 : 要检测日期,2015-10-11 是不是YYYY-MM-DD的格式。 : if (!startDate.matches("\d{4}-\d{2}-\d{2}")) { : throw new Exception("ERROR: startDate " + startDate + " is : invalid."); : } : reviewer说,Please compile the pattern + matcher, and use the matcher to : match the dates. : 我问,值得么? : 他说。In terms of performance, yes. : 这个真的很大的performance 的关系么?
s*r
20 楼
1 yes 2 如果constructor很复杂,可以用builder pattern,比较清楚
p*g
21 楼
第一个代码根本不对啊,此模式不能查出所有非法日期。建议用joda
j*r
22 楼
1. Not needed unless it's in a loop or in critical path. But you can't say reviewer is picky. 2. Point to Java 8 streaming and ask them to fuck off.
b*y
23 楼
算,但是给人打工就是这样了。。。工作要么忍要嘛滚
u*8
24 楼
谢谢。 还有 for (String line; (line = reader.readLine()) != null;) { 他说要 Use a while loop as is standard. Or use the IOUtils to read fully. 这算么?
【在 u***8 的大作中提到】 : 要检测日期,2015-10-11 是不是YYYY-MM-DD的格式。 : if (!startDate.matches("\d{4}-\d{2}-\d{2}")) { : throw new Exception("ERROR: startDate " + startDate + " is : invalid."); : } : reviewer说,Please compile the pattern + matcher, and use the matcher to : match the dates. : 我问,值得么? : 他说。In terms of performance, yes. : 这个真的很大的performance 的关系么?
如果你的matches是在一个loop里头,在外面compile the pattern很提高速度。
【在 u***8 的大作中提到】 : 要检测日期,2015-10-11 是不是YYYY-MM-DD的格式。 : if (!startDate.matches("\d{4}-\d{2}-\d{2}")) { : throw new Exception("ERROR: startDate " + startDate + " is : invalid."); : } : reviewer说,Please compile the pattern + matcher, and use the matcher to : match the dates. : 我问,值得么? : 他说。In terms of performance, yes. : 这个真的很大的performance 的关系么?
u*8
40 楼
问题就是不在loop里面。
【在 d******k 的大作中提到】 : 如果你的matches是在一个loop里头,在外面compile the pattern很提高速度。
【在 u***8 的大作中提到】 : 要检测日期,2015-10-11 是不是YYYY-MM-DD的格式。 : if (!startDate.matches("\d{4}-\d{2}-\d{2}")) { : throw new Exception("ERROR: startDate " + startDate + " is : invalid."); : } : reviewer说,Please compile the pattern + matcher, and use the matcher to : match the dates. : 我问,值得么? : 他说。In terms of performance, yes. : 这个真的很大的performance 的关系么?