Snippets tagged “reflection”
14 snippets use this tag.
- Access restriction on class due to restriction on required library rt.jar?Java
If you are getting an "access restriction" error on a class in your Java code, it means that you are trying to access a class or member (field or method) that has restricted access.
- Best practices to test protected methods with PHPUnitPHP
There are a few ways you can test protected methods using PHPUnit:
- Can you find all classes in a package using reflection?Java
Yes, it is possible to find all classes in a package using reflection in Java.
- Create instance of generic type in Java?Java
To create an instance of a generic type in Java, you can use the newInstance() method of the Class class, along with the Type and TypeVariable classes.
- Get generic type of class at runtimeJava
If you want to get the generic type of a class at runtime, you can use the Type class in the System namespace.
- How do I get a class instance of generic type T?Java
To get a class instance of a generic type T, you can use the new operator and specify the type argument when creating an instance of the class. Here's an example:
- How do I invoke a Java method when given the method name as a string?Java
To invoke a Java method when given the method name as a string, you can use reflection. Reflection is a feature of the Java language that allows you to inspect and manipulate classes, fields, and methods at runtime.
- How do I test a class that has private methods, fields or inner classes?Java
To test a class that has private methods, fields, or inner classes, you can do the following:
- How to use Class<T> in Java?Java
In Java, the Class<T> class represents the class or interface type of a class at runtime.
- Reflection generic get field valueJava
To get the value of a generic field using reflection in Java, you can use the get() method of the Field class, which returns the value of the field as an Object.
- Testing Private method using mockitoJava
It is generally considered bad practice to test private methods, as they are an implementation detail that should not be exposed to the outside world.
- What are all the different ways to create an object in Java?Java
In Java, you can create an object in the following ways:
- What could cause java.lang.reflect.InvocationTargetException?Java
The java.lang.reflect.InvocationTargetException is a checked exception that is thrown when an exception is thrown by an invoked method or constructor.
- What is reflection and why is it useful?Java
Reflection is a feature of the Java language that allows you to inspect and manipulate classes, fields, and methods at runtime.