为了之后方便查看,如今记录将倒序! 最后更新:2012-03-18html
5.这些API看来还须要修改,须要我帮忙吗?不过我还不了解View.java
来自android-2.3.3/android.view.View类,约3760行处。android
/** * @hide */ public void dispatchStartTemporaryDetach() { onStartTemporaryDetach(); } /** * This is called when a container is going to temporarily detach a child, with * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. * It will either be followed by {@link #onFinishTemporaryDetach()} or * {@link #onDetachedFromWindow()} when the container is done. */ public void onStartTemporaryDetach() { removeUnsetPressCallback(); mPrivateFlags |= CANCEL_NEXT_UP_EVENT; } /** * @hide */ public void dispatchFinishTemporaryDetach() { onFinishTemporaryDetach(); } /** * Called after {@link #onStartTemporaryDetach} when the container is done * changing the view. */ public void onFinishTemporaryDetach() { }
由于onStartTemporaryDetach()方法才有方法体。onFinish的就没有了。
可是仍是写在哪里仍是公开了。看来写代码的人员很讲究对称美嘛!哈哈,就算空的也要摆出来好看呗!网络
1.今天想看Java网络通讯,翻开了HttpURLConnection类。有喜感的东西出现了:它不该该出如今这里。socket
(1)来自Java Sun JDK中的源代码:ide
/** * HTTP Status-Code 500: Internal Server Error. * @deprecated it is misplaced and shouldn't have existed. */ @Deprecated public static final int HTTP_SERVER_ERROR = 500; /** * HTTP Status-Code 500: Internal Server Error. */ public static final int HTTP_INTERNAL_ERROR = 500;
(2)来自android源代码中,这两个常量以下:this
/** * Numeric status code, 500: Internal error */ public static final int HTTP_INTERNAL_ERROR = 500; /** * Numeric status code, 500: Internal error * * @deprecated Use {@link #HTTP_INTERNAL_ERROR} */ @Deprecated public static final int HTTP_SERVER_ERROR = 500;
经过对比,上面的代码中,变量,HTTP_INTERNAL_ERROR 是正确的。HTTP_SERVER_ERROR是不当心才写到这里的吧,对不对?可是是从Java出生时起这个小错,就得一直存在了。由于这个是公开的常量。惋惜的是我如今还不明白为何用HTTP_SERVER_ERROR这样名字就错了,谁能告诉我啊?
2.重构条件判断与写代码人情感。spa
在android源代码中SQLiteOpenHelper类中的getWritableDatabase()和getReadableDatabase()方法中.net
都有判断mDatabase的if语句:2.3.3及以前的版本是这样的:code
if (mDatabase != null && mDatabase.isOpen() && !mDatabase.isReadOnly()) { return mDatabase; // The database is already open for business }
在4.0.3中是下面这样的:
if (mDatabase != null) { if (!mDatabase.isOpen()) { // darn! the user closed the database by calling mDatabase.close() mDatabase = null; } else if (!mDatabase.isReadOnly()) { return mDatabase; // The database is already open for business } }
我以为把多重条件判断分开写确定会可读性好点,在《重构》一书中,我好像发现有相似的重构。
可是如今没有书在身边那。喜感的是,这个重构后的代码中注释多了,也有很口语化的文字。darn! Google后知道在这里应该是,该死的。意思。哈哈。
换成,damn or fuck?
3. 喜感的空方法啊!
看java.net.Socket类最后一个方法,JDK_API文档说了一大堆啊:
可是事实是这样的:
* @since 1.5 */ public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) { /* Not implemented yet */ }
看看android4.0.3中java.net.Socket中的这个方法:
/** * Sets performance preferences for connectionTime, latency and bandwidth. * * <p>This method does currently nothing. * * @param connectionTime * the value representing the importance of a short connecting * time. * @param latency * the value representing the importance of low latency. * @param bandwidth * the value representing the importance of high bandwidth. */ public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) { // Our socket implementation only provide one protocol: TCP/IP, so // we do nothing for this method }
哈哈,在android中的代码注释中有一些缘由,在javadoc中也说了这个方法是空的。可是
sun的那个没有说明啊。坑爹啊!我不明白既然这个方法为空,为何要公开这么一个方法呢?
4. android自定义的javadoc @hide
我是在java.net.Socket类中首次发现的:
/** * @hide internal use only */ public FileDescriptor getFileDescriptor$() { return impl.fd; }
这是让我发现变量名方法名还可使用$符号,呵呵,我之前都没有使用过啊。
关于android中的这个@hide自定义javadoc的其它特色,这个帖子遇到的问题,可能帮助你理解: