0

2 シンボル エラーが見つかりません。これは、クラス パスの結果ではないようです。また、listinterface.java コードから .add メソッドを pex6.java で動作させるのに問題があります。タイプに整数を使用していて、 add メソッドが無効なためかどうかはわかりませんが、わかりません。私はJavaを約6か月間使用しているので、まだJavaに慣れていません。何か不足している場合はお知らせください。

public interface ListInterface<T>
{


/**
 * Should return the number of elements contained within this list:
 */`enter code here`
int size ();


/**
 * Should return true if this list contains a copy of the given object:
 *
 * Comparisons should be performed by calling the equals(...) method of
 * each element, passing the given object as an argument
 */
boolean contains ( T theObject );


/**
 * Should remove the first element found within this list that exists as a
 * copy of the given object and return true if such an element was found:
 */
boolean remove ( T theObject );


/**
 * Should return a reference to the first element found within this list
 * that exists as a copy of the given object or null if no such element was
 * found:
 */
Object get ( T element );


/**
 * Should return a nicely formatted string representation of this list:
 */
String toString ();


/**
 * Should print the contents of this list to the screen:
 */
void writeLinkedList ();


/**
 * Should initialize this list for iteration (use of the getNext() method):
 */
void reset ();


/**
 * Should return a reference to the element located at the iterator's
 * current position and increment the iterator:
 *
 * If the iterator is currently pointing to the last element in this list,
 * the iterator should be reset to point to the first element in this list.
 *
 * @Preconditions:
 *     This list is not empty.
 *     This list has been reset.
 *     This list has not been modified since the last reset.
 */
  T getNext ();


/**
 * Should insert the given object onto the front of this list:
 */
void add ( T theObject );

}



public class PEX6
{
public static void main (String[] theArgs)
    {
        ListInterface<String> list = new RefList<T>();


            for (int i = 1; i <= 20; i++);
                {
                    int Random = ( ( int ) ( Math.random() * 4 ) );
                    list.add(new Integer(Random));

                    list.writeLinkedList();
                }
    }
private static int CountValue(ListInterface<T> theList,int theValue)
    {
        theList.clear();
        Integer nFound = 20;


        return nFound;
    }

}

エラー:

C:\Users\Linville\Documents\Assignment 6\PEX6.java:16: error: cannot find symbol
    private static int CountValue(ListInterface<T> theList,int theValue)
                                                ^
  symbol:   class T
  location: class PEX6
C:\Users\Linville\Documents\Assignment 6\PEX6.java:5: error: cannot find symbol
            ListInterface<String> list = new RefList<T>();
                                                     ^
  symbol:   class T
  location: class PEX6
C:\Users\Linville\Documents\Assignment 6\PEX6.java:11: error: method add in interface ListInterface<T> cannot be applied to given types;
                        list.add(new Integer(Random));
                            ^
  required: String
  found: Integer
  reason: actual argument Integer cannot be converted to String by method invocation conversion
  where T is a type-variable:
    T extends Object declared in interface ListInterface
3 errors

Tool completed with exit code 1

ちなみに、PEX6.java は決して完成していませんが、先に進んでコードを正しくコンパイルして、完了時に多くのエラーを修正する必要がないようにしたいと考えています。

4

2 に答える 2

0

にはありませんTPEX6、あなたはそれを参照しています:

ListInterface<String> list = new RefList<T>();
                                         ^ here

private static int CountValue(ListInterface<T> theList,int theValue)
                                            ^ and here

TまたはのいずれかStringに置き換える必要がありますIntegerlist2 つのうちどちらが意図されているかを判断することは不可能です。 asを宣言してListInterface<String>から、それに追加Integersします。

于 2013-04-12T18:07:27.990 に答える
0

T のタイプを渡す必要があります。ListInterface を文字列のリストにしたい場合

private static int CountValue(ListInterface<String> theList,int theValue)

于 2013-04-12T18:08:38.613 に答える