• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reflection

 
anita mitra
Greenhorn
Posts: 21
Eclipse IDE MySQL Database Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15452
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
anita mitra
Greenhorn
Posts: 21
Eclipse IDE MySQL Database Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot .. got it..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic