यह सच नहीं है कि आप केवल वास्तविक नहीं कक्षाएं पुरातन की कक्षा उदाहरणों मिल सकता है?
क्रमबद्ध करें।
लेकिन कभी-कभी आपको "आदिम पूर्णांक" के लिए कुछ मेटा-डेटा होना चाहिए। उदाहरण के लिए विधि हस्ताक्षर को देखते समय। फिर आपको पैरामीटर के लिए Class[]
मिलता है, और आपको किसी भी तरह public void test(Integer x)
और public void test(int x)
के बीच अंतर करने की आवश्यकता है।
तो इसे सुविधाजनक बनाने के लिए, प्राचीन प्रकार के लिए विशेष कक्षा के उदाहरण हैं।
इस एक कदम आगे ले करने के लिए, वहाँ भी java.lang.Void.TYPE है:
Class<Void> x = void.class;
व्यावहारिक Javadoc:
/**
* Determines if the specified <code>Class</code> object represents a
* primitive type.
*
* <p> There are nine predefined <code>Class</code> objects to represent
* the eight primitive types and void. These are created by the Java
* Virtual Machine, and have the same names as the primitive types that
* they represent, namely <code>boolean</code>, <code>byte</code>,
* <code>char</code>, <code>short</code>, <code>int</code>,
* <code>long</code>, <code>float</code>, and <code>double</code>.
*
* <p> These objects may only be accessed via the following public static
* final variables, and are the only <code>Class</code> objects for which
* this method returns <code>true</code>.
*
* @return true if and only if this class represents a primitive type
*
* @see java.lang.Boolean#TYPE
* @see java.lang.Character#TYPE
* @see java.lang.Byte#TYPE
* @see java.lang.Short#TYPE
* @see java.lang.Integer#TYPE
* @see java.lang.Long#TYPE
* @see java.lang.Float#TYPE
* @see java.lang.Double#TYPE
* @see java.lang.Void#TYPE
* @since JDK1.1
*/
public native boolean isPrimitive();
मैं जेनरिक और प्रकार विलोपन की वजह से "के तर्क का पालन नहीं करते ... क्या यह सच नहीं है कि आप केवल वास्तविक वर्गों के 'कक्षा' उदाहरण प्राप्त कर सकते हैं [और] प्राइमेटिव नहीं? " जेनेरिक और टाइप एरर के पास कक्षाओं और प्राइमेटिव के बीच अंतर के साथ कुछ लेना देना नहीं है। –
आपको 'void.class' पसंद है :-) – Thilo