I'm reading the book Algorithms and they mentioned a data type Item
. However, I can't find it in any of the API. Does "Item" data type exist in java?
"The name Item is a type paramter, a symbolic placeholder for some concrete type to be used by the client."
Java™ Classes A-Z. Item (Java™) Represents a discrete value or set of values in a document.
Yes. Every class >>is<< a type, so therefore it can be >>used<< as a type.
The name of a class can be used as a type, so you can declare an object-type variable or specify that a method returns an object.
On page 124, Sedgwick writes
"The name Item is a type paramter, a symbolic placeholder for some concrete type to be used by the client."
public class FixedCapacityStack<Item>
It's just a Generic Type:
http://docs.oracle.com/javase/tutorial/java/generics/types.html
public class Box<T> {
private T t;
public void set(T t) { this.t = t; }
public T get() { return t; }
}
Sedgwick uses "Item" instead of "T" because a Stack of "Item" was easier to read than a Stack of "T". The point is you can put anything in there, although according to the Java documentation you should follow a naming convention:
E - Element (used extensively by the Java Collections Framework) K - Key N - Number T - Type V - Value S,U,V etc. - 2nd, 3rd, 4th types
which clearly he decided not to!
No, there's no Item in the JDK 6 javadocs. That must be a custom class that Sedgewich wrote. Maybe you mean the ITEM interface on page 272 of the 4th edition:
http://books.google.com/books?id=hyvdUQUmf2UC&pg=PA272&lpg=PA272&dq=sedgewick+Item+class&source=bl&ots=kASI71PjAc&sig=BACGl1Q9nj43vhPwG8RVtO7euwI&hl=en&sa=X&ei=DnYIT42GDqTX0QGthpSTAg&ved=0CCAQ6AEwAA#v=onepage&q&f=false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With