aspose file tools*
The moose likes Java in General and the fly likes reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "reflection" Watch "reflection" New topic
Author

reflection

anita mitra
Greenhorn

Joined: Jul 03, 2009
Posts: 21

suppose i have a stubclass object... i am trying to get the details from stubclss using reflection concept

this is the code

and getCost method is


i couldn't understand these lines-
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

Let's look at those three lines:

1. Declares an array of Class objects and initializes it with two elements, which are both String.class (the Class object of class String).

2. Uses the reflection API to find a method named "getCost" which takes two strings as arguments. In other words, the class that "myclass" refers to must have a method that looks like this:

public ... getCost(String arg1, String arg2)

(the return type is not specified).

3. Creates a new Object array with two strings, with the values "chennai" and "goa".

Note: It is never necessary to create a new String object from a literal like is done in line 3. This should have been written like this:

Object[] args = new Object[] { "chennai", "goa" };

Shorter, easier to read and doesn't create unnecessary String objects.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
anita mitra
Greenhorn

Joined: Jul 03, 2009
Posts: 21

thanks a lot .. got it..
 
wood burning stoves
 
subject: reflection