简体   繁体   English

使用反射传递Double类型的参数

[英]Passing argument of type Double using Reflection

I'm trying to use reflection in a situation where I need to pass in arguments that have a type Double. 我试图在需要传递具有Double类型参数的情况下使用反射。 My code works perfectly when I call the function directly, but it fails when I do it via reflection with two doubles as its arguments. 当我直接调用该函数时,我的代码可以正常工作,但是当我通过以两个双精度数作为参数的反射来执行该代码时,它会失败。 Here is the eror: 这是错误:

java.lang.NoSuchMethodException: org.jinstagram.Instagram.searchMedia(java.lang.Double, java.lang.Double)

Double lat = Double.parseDouble(methodArgument[0][0]);
Double lng = Double.parseDouble(methodArgument[0][1]);
Method m = instagram.getClass().getDeclaredMethod("searchMedia", Double.class, Double.class);
Object o = (Object) m.invoke(instagram, lat, lng);

Just for testing, I can call this successfully like this: 只是为了测试,我可以这样成功地调用它:

Object o = instagram.searchMedia(lat, lng);

so the problem must be somewhere in the use of reflection, right? 所以问题一定在使用反射的地方吧?

The signature of the method in question is 该方法的签名是

public MediaFeed searchMedia(double latitude, double longitude)
                                                             throws InstagramException

So you need to use double.class instead of Double.class 因此,您需要使用double.class而不是Double.class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM