के आमंत्रण के लिए स्पष्ट रूप से डाला जाना चाहिए, कृपया निम्नलिखित उदाहरण देखें, getMethod()
पर पहली कॉल ग्रहण में चेतावनी उत्पन्न करती है। दूसरा काम नहीं करता है और NoSuchMethodException
के साथ विफल रहता है।टाइप नल का तर्क स्पष्ट रूप से कक्षा <?> [] को varargs विधि
The argument of type
null
should explicitly be cast toClass<?>[]
for the invocation of the varargs methodgetMethod(String, Class<?>...)
from typeClass<Example>
. It could alternatively be cast to Class for a varargs invocation.
मैंने चेतावनी का पालन किया और अब कुछ भी काम नहीं किया।
Exception in thread "main" java.lang.NoSuchMethodException:
Example.exampleMethod(null)
at java.lang.Class.getMethod(Class.java:1605)
at Example.main(Example.java:12)
किसी ने मुझे इस व्यवहार की व्याख्या कर सकते:
import java.lang.reflect.Method;
public class Example
{
public void exampleMethod() { }
public static void main(String[] args) throws Throwable
{
Method defaultNull = Example.class.getMethod("exampleMethod", null);
Method castedNull = Example.class.getMethod("exampleMethod", (Class<?>) null);
}
}
दूसरी कॉल इस त्रुटि पैदा करता है? चेतावनी से बचने का सही तरीका क्या है?
एक जाली 'शून्य' कैसे एक अनदेखा 'शून्य' से अलग होता है? मैं इसे जेडीके स्रोत कोड में नहीं देख सकता। – codevour
कृपया अद्यतन पोस्ट पर देखें। – StKiller