• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Call java Class method without reflection

 
Gaurav Gupta Ser
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to call java class Method by passing parameter where class name , method name and list of parameter are stored in xml ..
I can call dynamically method of class through reflection but I don't want to call it through reflection because EJB 3.1 has some restriction to use Reflection as described in EJB 3.1 specification , 21.2.2 Programming Restrictions.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch! The spec doesn't say you can't use reflection. It says you can't use reflection in certain ways.

A direct code from the spec is:
The enterprise bean must not attempt to query a class to obtain information about the declared members that are not otherwise accessible to the enterprise bean because of the security rules of the Java language. The enterprise bean must not attempt to use the Reflection API to access information that the security rules of the Java programming language make unavailable.
 
Gaurav Gupta Ser
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sir for your reply ,
But may you clarify , what would be best practice to call Java Class Method with parameter at runtime where Class and Method name is stored in String form that would not cause too much memory load at enterprises level in projects (ex. banking solution).
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav,
I'm female, let's not call me "sir."

I can only think of two options
1) Reflection
2) Cache the expected classes in a map and look it up from that map.

Personally, I'd use reflection. Unless you are running reflection in a tight loop, it is unlikely to be a performance problem. Or design the app so it doesn't pass class information as a String. For a banking application, I wouldn't store the class/method names in the form anyway - too much info for the user.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic