Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright 2002-2007 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 */

import java.lang.reflect.Method;

public class Main {
    /**
     * Given a method, which may come from an interface, and a target class used in the current reflective invocation, find the corresponding target method if there is one. E.g. the method may be <code>IFoo.bar()</code> and the target class may be <code>DefaultFoo</code>. In this case, the method may be <code>DefaultFoo.bar()</code>. This enables attributes on that method to be found.
     * <p>
     * <b>NOTE:</b> In contrast to {@link org.springframework.aop.support.AopUtils#getMostSpecificMethod}, this method does <i>not</i> resolve Java 5 bridge methods automatically. Call {@link org.springframework.core.BridgeMethodResolver#findBridgedMethod} if bridge method resolution is desirable (e.g. for obtaining metadata from the original method definition).
     * 
     * @param method
     *          the method to be invoked, which may come from an interface
     * @param targetClass
     *          the target class for the current invocation. May be <code>null</code> or may not even implement the method.
     * @return the specific target method, or the original method if the <code>targetClass</code> doesn't implement it or is <code>null</code>
     * @see org.springframework.aop.support.AopUtils#getMostSpecificMethod
     */
    public static Method getMostSpecificMethod(Method method, Class<?> targetClass) {
        if (method != null && targetClass != null) {
            try {
                method = targetClass.getMethod(method.getName(), method.getParameterTypes());
            } catch (NoSuchMethodException ex) {
                // Perhaps the target class doesn't implement this method:
                // that's fine, just use the original method.
            }
        }
        return method;
    }
}