Class<?> cls = Class.forName(className);
But your className
should be fully-qualified – i.e. com.mycompany.MyClass
More Related Contents:
- How to read the value of a private field from a different class in Java?
- How to load Classes at runtime from a folder or JAR?
- Get all of the Classes in the Classpath
- What is the difference between a.getClass() and A.class in Java?
- Method to dynamically load java class files
- How to get the Array Class for a given Class in Java?
- Check if a Class Object is subclass of another Class Object in Java
- Instantiate private inner class with java reflection
- Java: Multiple class declarations in one file
- Java : If A extends B and B extends Object, is that multiple inheritance
- Creating a variable name using a String value
- Avoiding instanceof in Java
- Is a Java string really immutable?
- How to get the MethodInfo of a Java 8 method reference?
- what is the Class object (java.lang.Class)?
- What is java pojo class, java bean, normal class? [duplicate]
- Is there something like instanceOf(Class c) in Java?
- Can I get all methods of a class?
- How to get the parent base class object super.getClass()
- How to get annotations of a member variable?
- Java reflection: how to get field value from an object, not knowing its class
- Set field value with reflection
- Java dynamic function calling
- Reflection for Class of generic parameter in Java?
- What is the difference between getFields and getDeclaredFields in Java reflection
- Dynamically find the class that represents a primitive Java type
- Import a custom class in Java
- Synthetic Class in Java
- Instantiate a class object with constructor that accepts a string parameter?
- How to prevent public methods from being called from specific classes