問(wèn)題描述
來(lái)自Calendar.before(Object when)
的javadoc:
From the javadoc of Calendar.before(Object when)
:
返回此日歷是否表示指定對(duì)象表示的時(shí)間之前的時(shí)間.該方法等價(jià)于:
Returns whether this Calendar represents a time before the time represented by the specified Object. This method is equivalent to:
compareTo(when) < 0
當(dāng)且僅當(dāng) when 是 Calendar 實(shí)例.否則,該方法返回 false.
if and only if when is a Calendar instance. Otherwise, the method returns false.
如果當(dāng)有人傳遞不是 Calendar 實(shí)例的東西時(shí)它返回 false,為什么它會(huì)接受 Object?為什么不直接接受 Calendar 實(shí)例?這讓我在很長(zhǎng)一段時(shí)間內(nèi)一直在關(guān)注某個(gè)功能中的不正確結(jié)果.
Why does it accepts an Object if when someone passes something that's not a Calendar instance it returns false? Why not just accepting a Calendar instance? This kept me watching for uncorrect results in a functionality for quite some time.
推薦答案
我認(rèn)為沒(méi)有什么特別的原因.java.util.Calendar
有一些設(shè)計(jì)問(wèn)題,我們不得不忍受,很遺憾.
I think there is no particular reason for that. java.util.Calendar
has some design issues we have have to live with, unfortunately.
這篇關(guān)于Calendar.before(Object when),為什么是Object?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!