本帖最后由 陈潼 于 2012-8-16 20:33 编辑
- //public static <T> int binarySearch(List<? extends Comparable< ? super T>> list,T target)//怎么回事?:??正常
- //public static <T> int binarySearch(List<T extends Comparable< ? super T>> list,T target)//怎么回事?:??错误
- //public static <T extends Comparable< ? super T>> int binarySearch(List<T> list,T target)//怎么回事?:??正常
- {
- int max,min,mid ;
- max = list.size()-1;
- min = 0 ;
- while(min <= max)
- {
- mid = (max+min)>>1
- int num = list.get(mid).compareTo(target);
- if(num > 0)
- {
- max = mid -1 ;
- }
- else if (num < 0)
- {
- min = mid + 1 ;
- }
- else
- {
- return num ;
- }
- }
- return -min-1;
- }
- }
复制代码 如题,将方法头的注释取消后可见各个方法头,正确的可以理解,但是没想明白为什么第二个是错的。请高手解答 |
|