鄙人想请各位大侠给出,返回类型不一样的重载方法的代码

解决方案 »

  1.   

    public void show()
      {
          System.out.println("hello");
      }
     public int show(int a)
     {
         System.out.println("hello");
         return 2;
     }
    只能是这样写了,只是返回类型不同的重载是不允许的,这是有道理的,你可以参考java 编程思想,我很喜欢这本书
      

  2.   

    找个 牛逼的点 给你看看 哈哈 public E remove(int index) {
    RangeCheck(index); modCount++;
    E oldValue = (E) elementData[index]; int numMoved = size - index - 1;
    if (numMoved > 0)
        System.arraycopy(elementData, index+1, elementData, index,
         numMoved);
    elementData[--size] = null; // Let gc do its work return oldValue;
        }    /**
         * Removes the first occurrence of the specified element from this list,
         * if it is present.  If the list does not contain the element, it is
         * unchanged.  More formally, removes the element with the lowest index
         * <tt>i</tt> such that
         * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
         * (if such an element exists).  Returns <tt>true</tt> if this list
         * contained the specified element (or equivalently, if this list
         * changed as a result of the call).
         *
         * @param o element to be removed from this list, if present
         * @return <tt>true</tt> if this list contained the specified element
         */
        public boolean remove(Object o) {
    if (o == null) {
                for (int index = 0; index < size; index++)
    if (elementData[index] == null) {
        fastRemove(index);
        return true;
    }
    } else {
        for (int index = 0; index < size; index++)
    if (o.equals(elementData[index])) {
        fastRemove(index);
        return true;
    }
            }
    return false;
        }