简体   繁体   中英

getParameters() should return an array and this code should succeed in the jdk 7 maven project

private void setPropertiesToBasePojoMarkerImpl(Object obj, Method[] methods) {
    for (Method method : methods) {
        if (method.getName().contains("get") 
                && !method.isAnnotationPresent(Worker.class)
                && !method.getName().contains("getClass") 
                && isPojoMarkerMethod(method)
                && method.getParameters().length == 0) {
            // in the above condition it says the method getParameters() is undefined for type Method
            try {
                Serializable result = (Serializable) method.invoke(obj, new Object[0]);
                if (result != null) {
                    if (staticRegistry.isReferencePresent(result) != null)
                        result = staticRegistry.isReferencePresent(result);
                }
                String propname = method.getName().toString().substring(3).toLowerCase();
                beanEnhancer.getServerBasePojoMarkerImpl().setProperty(propname, result);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                logger.log(Level.WARNING, "unable to invoke method with name" + method.getName() + " " + e);
            }
        }
    }
}

So the issue here is that its a maven project with JDK 7 source configuration. It builds flawlessly on linux and windows machines. On my mac book pro it consistently says the said method is unavailable for type Method.

I am certain this method should be available on all builds of JDK 7.

Any clues ?

Method.getParameters() was introduced in JDK 8. Perhaps you're looking for Method.getParameterTypes()?

The source level only controls what language features the compiler will accept, not what JDK jars get compiled against.

Check to see what version of the Java compiler your Maven installation on your MBP is using. If it is finding a 1.7 compiler, it's probably finding a JAR containing the 1.7 versions of the JDK classes, where java.lang.reflect.Method doesn't have a method called getParameters() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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