1700453430
说明为什么要这样做,而不是怎么做的,比如解决了哪个Bug,方法过时的原因是什么。像这样一个注释就是好的:
1700453431
1700453432
public class BasicDataSource implements DataSource{
1700453433
1700453434
static{
1700453435
1700453436
//Attempt to prevent deadlocks-see DBCP-272
1700453437
1700453438
DriverManager.getDrivers();
1700453439
1700453440
}
1700453441
1700453442
}
1700453443
1700453444
(3)警示性注释
1700453445
1700453446
这类注释是我们经常缺乏的,或者是经常忽视的(即使有了,也常常是与代码版本不匹配),比如可以在注释中提示此代码的缺陷,或者它在不同操作系统上的表现,或者警告后续人员不要随意修改,例如tomcat的源码org.apache.tomcat.jni.Global中有这样一段注释:
1700453447
1700453448
public class Global{
1700453449
1700453450
/**
1700453451
1700453452
*Note:it is important that the APR_STATUS_IS_EBUSY(s)
1700453453
1700453454
*macro be used to determine
1700453455
1700453456
*if the return value was APR_EBUSY, for portability reasons.
1700453457
1700453458
*@param mutex the mutex on which to attempt the lock acquiring.
1700453459
1700453460
*/
1700453461
1700453462
public static native int trylock(long mutex);
1700453463
1700453464
}
1700453465
1700453466
(4)TODO注释
1700453467
1700453468
对于一些未完成的任务,则增加上TODO提示,并标明是什么事情没有做完,以方便下次看到这个TODO标记时还能记忆起要做什么事情,比如在DBCP源代码中有这样的TODO注释:
1700453469
1700453470
public class DelegatingStatement extends……implements……{
1700453471
1700453472
/*
1700453473
1700453474
*Note was protected prior to JDBC 4
1700453475
1700453476
*TODO Consider adding build fags to make this protected
1700453477
1700453478
*unless we are using JDBC 4.
1700453479
[
上一页 ]
[ :1.70045343e+09 ]
[
下一页 ]