Skip to content
Advertisement

Tag: reflection

Reflection generic get field value

I am trying to obtain a field’s value via reflection. The problem is I don’t know the field’s type and have to decide it while getting the value. This code results with this exception: Can not set java.lang.String field com….fieldName to java.lang.String I tried to cast, but I get compilation errors: or How can I do this? Answer Like answered

calling numbered function name in loop using java reflection

i have a problem as : MyFirstClass.java MySecondClass.java TestClass.java I want to use java reflection and call the pObj.getP**Param() methods in for loop by providing the parameters to g How it can be made possible. I don’t want to use array of p*Params. Thanks in advance. Answer Are you sure this is what you need? For me, your code seems

Change private static final field using Java reflection

I have a class with a private static final field that, unfortunately, I need to change it at run-time. Using reflection I get this error: java.lang.IllegalAccessException: Can not set static final boolean field Is there any way to change the value? Answer Assuming no SecurityManager is preventing you from doing this, you can use setAccessible to get around private and

Java – Get a list of all Classes loaded in the JVM

I would like to get a list of all the classes belonging to a certain package as well as all of their children. The classes may or may not be already loaded in the JVM. Answer Well, what I did was simply listing all the files in the classpath. It may not be a glorious solution, but it works reliably

Simple way to get wrapper class type in Java

I have a piece of code where I need to pass the class of a field in a method. Because of the mechanics of my code I can only handle reference objects and not primitives. I want an easy way of determining if a Field’s type is primitive and swap it with the appropriate wrapper class. So in code what

Is there a general “back-end” library for Java reflection

I’m currently working with a specialized, interpreted, programming language implemented in Java. As a very small part of the language, I’d like to add the ability to make calls into Java. Before I dive into all of the nitty-gritty of reflection, I was wondering if anyone knew of a general library for doing the “back-end” part of invoking Java code

Advertisement