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

--Use Reflective

Documents for the development of and with JVx.

--Use Reflective

Postby Development@SIB » Wed Aug 01, 2012 4:47 pm



This article is outdated - please use our new system at

https://doc.sibvisions.com




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

How it works?

We have a short example for you. Our class:

Code: Select all
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:

Code: Select all
Object oClient = Reflective.construct("com.sibvisions.app.MyClient");

Reflective.call(oClient, "doUpload", "Key", "Value");

Now we call doDownload:

Code: Select all
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, same number of parameters but with different parameter types. Without this class, it is not guaranteed that the desired method is called.
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation