Static class properties with Class<MyClass> myClass
<p>I am experimenting here a bit. </p>

<p>Say I have a class : </p>

<pre><code>static class MyClass {
    static String property = "myProperty";
}
</code></pre>

<p>and a method: </p>

<pre><code>public static void myMethod0(Class&lt;MyClass&gt; clazz)  {
   try {
        MyClass myClass = clazz.newInstance();
        System.out.println (myClass.property);
    } catch (Exception e) {
        e.printStackTrace();
    } 
}
</code></pre>

<p>and to test it: </p>

<pre><code>public static void main(String[] args ) {
    myMethod0(MyClass.class);
}
</code></pre>

<p>myMethod0 would work here, however, I am creating a new instance in order to reach the property. 
Since the properties are static I should be able to reach them without actually creating any instance. For example as you would do when reaching a static property, ie <strong>MyClass.property</strong></p>

<p>To summarize: 
Is it possible to reach the static property of MyClass, by having Class clazz = MyClass.class ?</p>

<p>Thanks ! </p>

<p>**</p>

<h2>EDIT:</h2>

<p>**
To put the above in perspective and what I am actually trying to accomplish: </p>

<pre><code>public static class PDF_1 { public static PDF_1 it = new PDF_1();
    static String contentType = "application/pdf";
    static String fileEnding = "pdf";
}
static void myMethod0(PDF_1 pdf) {
    System.out.println(pdf.fileEnding);
}


public enum PDF_2 {it;
    static String contentType = "application/pdf";
    static String fileEnding = "pdf";        
}
static void myMethod1(PDF_2 pdf) {
   System.out.println(pdf.fileEnding);
}  

public static void main(String[] args ) {
    myMethod0(PDF_1.it); // Works fine! However very verbose because of public static PDF_1 it = new PDF_1();
    myMethod1(PDF_2.it); // Works fine! Somewhat verbose though because of the "it" keyword        
}
</code></pre>

<p>The whole idea as to what I am trying to accomplish with this, is that too often do I see people declare lots of strings, ie: </p>

<pre><code>static class Constants {
    static String PDF_CONTENT_TYPE = "application/pdf";
    static String PDF_FILE_ENDING = "pdf";

    static String HTML_CONTENT_TYPE = "text/html";
    static String HTML_FILE_ENDING = "html";
}

// There is no way knowing what type the method actually wants. Is it contentType, fileEnding or something entirely different ? 
public void myMethod(String str) {

}
</code></pre>

<p>What I am trying to achieve is something that would allow you to pass a main class/enum, ie: PDF and the method will itself determine what it will use. The caller will just know what to pass, a PDF or HTML class/enum. I am also looking for something that is this refactor friendly as well. It is also of interest not to complicate the declaration of this creation. I find fully blown enums just as obtrusive as a class, and can be hard to read. The ide a is that I am just grouping the two strings in a parent object "PDF" and "HTML".  An enum: </p>

<pre><code>public enum SomeType {
    PDF("application/pdf", "pdf"), HTML(...);
    String contentType;
    String fileEnding;        
    // Constructor ... 
}
</code></pre>

<p>Would not allow you to declare a method and specify that this method expects the HTML stuff. Only that the enum type is of type SomeType. There is a risk that "someone" would pass SomeType.PDF to that method. What I am doing with the enum and class seems like a noob solution, and the Java language should provide a feature like this, or does it already?</p>

<p>Does this make sense? </p>
