Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does java contain a data type named "Item"?

Tags:

java

types

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?

like image 585
Gene Avatar asked Jan 07 '12 16:01

Gene


People also ask

Is item a data type in Java?

"The name Item is a type paramter, a symbolic placeholder for some concrete type to be used by the client."

What is the item type in Java?

Java™ Classes A-Z. Item (Java™) Represents a discrete value or set of values in a document.

Is class name data type in Java?

Yes. Every class >>is<< a type, so therefore it can be >>used<< as a type.

Can class name be a datatype?

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.


2 Answers

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!

like image 179
Lou Morda Avatar answered Oct 23 '22 06:10

Lou Morda


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

like image 39
duffymo Avatar answered Oct 23 '22 06:10

duffymo