神奇好望角 The Magical Cape of Good Hope

          庸人不必自擾,智者何需千慮?
          posts - 26, comments - 50, trackbacks - 0, articles - 11
            BlogJava :: 首頁 ::  :: 聯(lián)系 :: 聚合  :: 管理

          JDK 源代碼中的搞笑之處

          Posted on 2007-11-30 17:47 蜀山兆孨龘 閱讀(1116) 評(píng)論(0)  編輯  收藏
          JDK 源代碼中的搞笑之處 Funny Things in JDK Source
            雖然完整版的 JDK 源代碼現(xiàn)已開放了,但安裝在 Java\jdk[版本號(hào)] 目錄下的公共 src.zip 仍然是我最經(jīng)常參考的資源。每次我遇到一個(gè) API 問題,都會(huì)刊這個(gè)公共源代碼。解決問題之余,我還找到很多有趣的東西,有時(shí)還搞笑。這里距三個(gè)例子。     Though the full version of JDK source is available now, but the public src.zip installed under Java\jdk[version_number] directory is still my most frequent refered resource. Every time I encounter an API problem, this public source is read. And besides solving those problems, I've also found many interesting things which are sometimes also funny. Here are three exaples.
            大概從 JDK 5.0 開始,類 java.lang.Object 引入了一個(gè)叫 wait(long timeout, int nanos) 的方法。等等,nanos,納秒?眾所周知,即使在強(qiáng)大的 Windows 多媒體 API 里面,計(jì)時(shí)器的精度也只有一毫秒,也就是一兆納秒。盡管 Java 非常棒,但不能處理納秒。而源代碼證明了這一點(diǎn),納秒被舍入到最接近的毫秒,0 或 1……精彩……     Maybe since JDK 5.0, a method called wait(long timeout, int nanos)is introduced into Class java.lang.Object.Object. Wait a minute, nanos, is it nanoseconds? It's no secret thst even in powerful Windows multimedia API, the precision of timer is only one millisecond, that is a million nanosecond. Though Java is pretty great, it can not deal with nanoseconds. And the source proves it, that nanoseconds are rounded to the nearest millisecond, 0 or 1... Amazing...
            今天我想得到一個(gè) JDialog 的所有者,但卻沒有 getOwner() 方法。最后我才明白 JDialog 的所有者就是它的父組件,用 getParent() 就可以了。那現(xiàn)在所有者等同于父級(jí)了?     Today I wanted to get a JDialog's owner, but there's no method called getOwner(). Finally I was awear that the owner of a JDialog is exactly its parent component, and just using getParent() is okey. So owner is synonymous with parent now?
            最后,我想提下 JSpinner 的實(shí)現(xiàn)有錯(cuò)。一些安裝在 JSpinner 上的偵聽器絲毫不起作用。我在 JSpinner.java 里找到這段注釋:“還是不對(duì),我們沒其他辦法了,SpinnerModelJFormattedTextField 現(xiàn)已不同步了。”JDK 的開發(fā)者的誠實(shí)值得感謝。我的解決方法是直接操控復(fù)合式組件 JSpinner 中的 JFormattedTextField     At last, I wanna mention the JSpinner implementation is bugged. Some kinds of listener installed on a JSpinner take no effect at all. I found this comment in JSpinner.java: "Still bogus, nothing else we can do, the SpinnerModel and JFormattedTextField are now out of sync." The JDK developers deserve a thank for honesty. My solution is to directly manipulate the JFormattedTextField within JSpinner, a compound JComponent.

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 陕西省| 苍溪县| 大方县| 武夷山市| 思南县| 呼玛县| 商丘市| 通州市| 封丘县| 娄底市| 松滋市| 江门市| 宿迁市| 壶关县| 武川县| 交城县| 那曲县| 盐亭县| 颍上县| 阳谷县| 嘉荫县| 寻甸| 古蔺县| 客服| 潮安县| 土默特左旗| 延庆县| 阳新县| 石泉县| 苏州市| 垦利县| 山阳县| 轮台县| 大石桥市| 宣汉县| 云龙县| 屏东县| 正镶白旗| 乐清市| 化德县| 涿州市|