Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.Component;

public class Main {
    /**
     * Get specified parent.
     * @param <T>
     * @param component
     * @param clazz
     * @return
     */
    public static <T> T getParent(Component component, Class<T> clazz) {

        if (component == null) {
            return null;
        }

        if (clazz.isInstance(component)) {
            return (T) component;
        }

        return getParent(component.getParent(), clazz);
    }
}