Load class For Name - Java Reflection

Java examples for Reflection:Class

Description

Load class For Name

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String typeName = "java2s.com";
        System.out.println(classForName(typeName));
    }//from ww w  .  j a v a  2  s .  c o  m

    public static Class<?> classForName(String typeName) {
        try {
            return Class.forName(typeName);
        } catch (ClassNotFoundException e) {
            return null;
        }
    }
}

Related Tutorials