• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reflection

 
Greenhorn
Posts: 21
Eclipse IDE MySQL Database Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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-
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot .. got it..
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic