Java tutorial
//package com.java2s; /** * Copyright (C) 2011-2013 Barchart, Inc. <http://www.barchart.com/> * * All rights reserved. Licensed under the OSI BSD License. * * http://www.opensource.org/licenses/bsd-license.php */ import java.lang.reflect.Method; public class Main { public static <T extends Object, I, P extends I> T bind(final T component, final P param, final Class<I> type) { try { final Method m = findMethod(component, "bind", param, type); m.setAccessible(true); m.invoke(component, param); } catch (final Exception e) { throw new UnsupportedOperationException("Could not bind component", e); } return component; } public static <I, P extends I> Method findMethod(final Object obj, final String name, final P param, final Class<I> type) throws NoSuchMethodException { Class<?> c = obj.getClass(); while (c != null && c != Object.class) { try { return c.getDeclaredMethod(name, type); } catch (final Exception e) { } c = c.getSuperclass(); } throw new NoSuchMethodException(); } }