Documentation

Trace: Using Reflective

(jvx:common:util)

Using Reflective

JVx's reflective class allows you to create class instances or call methods via reflection but without directly using java.lang.reflect.

How does it work?

We have a short example for you. Our class:

MyClient.java
package com.sibvisions.app;
 
public class MyClient
{
   public Result doUpload(String pKey, String pValue)
   {
       ...
   }
 
   public Result doDownload(String pPath)
   {
       ...
   }
 
   public Result doDownload(File pFile)
   {
       ...
   }
 
}

A simple method call:

Object oClient = Reflective.construct("com.sibvisions.app.MyClient");
 
Reflective.call(oClient, "doUpload", "Key", "Value");

Now we call doDownload:

Object oClient = Reflective.construct("com.sibvisions.app.MyClient");
 
//no problem
Reflective.call(oClient, "doDownload", "file.txt");
 
//without Parameter, maybe we call the wrong method
Reflective.call(oClient, "doDownload", new Reflective.Parameter(String.class, null));

As you can see, we use the class Reflective.Parameter. It is useful if you have methods with the same name and same number of parameters but with different parameter types. Without this class, it is not guaranteed that the desired method is called.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information