0

後続の展開のために、この反復可能な Java クラスをシリアル化しようとしています。以下のクラスにSerializableタグを含めると、Java エラーが発生します。このコードは、リンク リスト データ構造を使用する汎用マルチ セット (バッグ) 実装であり、マルチ セット内で汎用アイテムを簡単に反復するためのイテレータ ユーティリティを実装します。コーディングのピクシーダストをまき散らして状況を救える人はいますか? Java Beans が典型的なドキュメントを作成するのを手伝ってください!!

/**my iterable class **
**/

public class Bagged<Item> implements Iterable<Item> {

private int n;
private Node first;

//create empty bag
public Bagged(){ first= null; n= 0; }

//check if bag is empty
public boolean empty(){return first==null;}
//add item
public void add(Item item){
    Node theold = first;
    first = new Node();
    first.item= item;
    first.nextnode = theold;
    n++;
}
//return the number of items
public int size(){return n;}

//create linked list class as a helper
private class Node{private Item item;  private Node nextnode; }

//returns an iterator that iterates over all items in thine bag
public Iterator<Item> iterator(){
 return new ListIterator();
} 

//iterator class--> remove() function ommited typical of a bag implementation.
private class ListIterator implements Iterator<Item>
    {
     private Node current = first;
     public void remove(){ throw new UnsupportedOperationException();}
     public boolean hasNext(){return current!=null;}
     public Item next() 
             {
        if(!hasNext())throw new NoSuchElementException();
            Item item = current.item;
            current = current.nextnode;
        return item;
             }
}
//main class omitted- end of iterable class.
}
4

1 に答える 1