| Author |
Class definition
|
Deepak Chandrashekar Avanna
Greenhorn
Joined: Oct 11, 2006
Posts: 7
|
|
Hello Ranchers, I had a question regarding the following assignment. Class cls = Item.class; Can anybody tell me where is class for Item defined as I have not defined the 'class' for my Item class. I checked JLS for Object but did not find it there. Thanks, Deepak
|
 |
Allan Jacobs
Greenhorn
Joined: Aug 28, 2006
Posts: 15
|
|
Hello Deepak, It is possible to do better than find the class file for you. Assuming that your .java file compiles then it should be possible to train you to find it yourself. If your program compiles then post the (1) package statement at the top of the file that contains the Item.class usage, (2) the import statements at the top of the same file, (3) your javac command line (especially any -classpath argument). If your javac command line contains no -classpath argument then post (3') the CLASSPATH setting for your environment.
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
This is taken directly from the documentation of the Class class.
public final class Class<T> extends Object implements Serializable, GenericDeclaration, Type, AnnotatedElement Instances of the class Class represent classes and interfaces in a running Java application. An enum is a kind of class and an annotation is a kind of interface. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects. Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader. ...It is also possible to get the Class object for a named type (or for void) using a class literal (JLS Section 15.8.2). For example: System.out.println("The name of class Foo is: "+Foo.class.getName());
(Emphasis mine) [ October 25, 2006: Message edited by: Garrett Rowe ]
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Matt Russell
Ranch Hand
Joined: Aug 15, 2006
Posts: 165
|
|
It's a class literal: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#251530 It's automatically defined by the language, so you don't have to declare it yourself.
|
Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Deepak Chandrashekar Avanna: ... Can anybody tell me where is class for Item defined as I have not defined the 'class' for my Item class...
Welcome to JavaRanch! I'm not entirely clear on what you're asking: Are you saying that you can't find a definition for Item.class? Or are you asking about the Class.class? It looks like both interpretations have been addressed above.
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Deepak Chandrashekar Avanna
Greenhorn
Joined: Oct 11, 2006
Posts: 7
|
|
Hi Allan, Thanks for the reply. I am not clear about your post. To put my question in better way, I just wanted to know where is the "class" in Item.class defined. Is it inherited from Object? Thanks, Deepak
|
 |
Deepak Chandrashekar Avanna
Greenhorn
Joined: Oct 11, 2006
Posts: 7
|
|
Thanks everybody. I got it. It is the literal. Thanks, Deepak
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Deepak Chandrashekar Avanna: ...I got it. It is the literal...
You might also be interested in this thread.
|
 |
 |
|
|
subject: Class definition
|
|
|