import javax.swing.JApplet; import java.awt.Graphics; import java.util.*; public class Test4 extends JApplet { public void init() { Set myTree = new TreeSet(); myTree.add(new StringBuilder("nocompile"); myTree.add(new StringBuilder("ornocompile"); } } public void paint(Graphics g) { } } class Widget implements Comparable { String item; public Widget (String item) { this.item = item; } public boolean equals(Object o) { if ((o instanceof Widget) && (((Widget)o).getItem() == this.item)) { return true; } else { return false; } } public int hashCode() { return (this.item.length()); } public String toString() { return this.item; } public String getItem() { return this.item; } public int compareTo(Object o) { return this.item.compareTo(((Widget)o).getItem()); } //This should be a generic method public String genMeth(T in) { return "The toString method on your object returns " + in.toString(); } }
Make your own free website on Tripod.com