File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes curly class field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "curly class field" Watch "curly class field" New topic
Author

curly class field

jack nick
Ranch Hand

Joined: Jan 11, 2001
Posts: 96
hi there,
sorry am making you guys read this big block of code for just a single field. Am talking about the field ErrorCode.class. Very obviously there is a reference made to a static field called class which must resided in the class declaration of ErrorCode or its parents. But it does not seem too.
Problem is why does this code not throw and error. The foreseeable functionality of the said statement is it assigns the ErrorCode class. But how, when and where does it do it from.

public class ErrorCode implements Comparable, Cloneable, java.io.Serializable {
private java.lang.String _name = "unknown";
public final static Class CLASS = ErrorCode.class;
public final static java.lang.String CLASSNAME = CLASS.getName();
public ErrorCode() {
}
public int compareTo(Object o) {
ErrorCode data = (ErrorCode) o;
return toString().compareTo(data.toString());
}
public String toString() {
return _name;
}
public static void main(String adr[]){
ErrorCode temp = new ErrorCode();
System.out.println("Class name "+ ErrorCode.CLASSNAME);
System.out.println("Class name from method "+ temp.getClass().getName());
}
}

Cheers
Jack
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
ErrorCode.class is a class literal, class is not something declared/defined in the ErrorCode class.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
See Section 15.8.2 of the Java Language Specification on Class Literals.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
...and you may want to take look at The Class class documentation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: curly class field