0
時間設置到時在格式hh:mm
通過例如8:00
的日期,下面的代碼按預期工作:MissingMethodException當我嘗試打電話給合作者方法
package demo
import static java.util.Calendar.*
class Helper {
public static final Date setTimeToDate(final Date date, final String time) {
Calendar calendar = date.toCalendar()
Integer hourOfDay = time.tokenize(':')[0].toInteger()
calendar.set hourOfDay: hourOfDay, minute: 0, second: 0
calendar.getTime()
}
}
現在我嘗試提取獲得一天的小時到它自己的方法的邏輯,所以我的代碼適應這種要求如下:
package demo
import static java.util.Calendar.*
class Helper {
public static final Date setTimeToDate(final Date date, final String time) {
Calendar calendar = date.toCalendar()
Integer hourOfDay = getHour(time)
calendar.set hourOfDay: hourOfDay, minute: 0, second: 0
calendar.getTime()
}
private Integer getHour(final String time) {
time.tokenize(':')[0].toInteger()
}
}
當我嘗試調用setTimeToDate方法
println Helper.setTimeToDate(new Date(), '8:00')
我收到以下錯誤
groovy.lang.MissingMethodException: No signature of method: static demo.Helper.getHour() is applicable for argument types: (java.lang.String) values: [8:00]
Possible solutions: getAt(java.lang.String)
at demo.Helper.setTimeToDate(Script1.groovy:9)
at demo.Helper$setTimeToDate.call(Unknown Source)
at demo.Script1.run(Script1.groovy:21)
我特別不理解的錯誤消息[8:00]