Home Java Reflect Getting information about Constructor
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Getting information about Constructor

Advertisement
In this section you will learn, how to retrieve the information about the constructor by using the getConstructors() method. Here is an example that provides the usage of the getConstructors() method.

Getting information about Constructor

     

In this section you will learn, how to retrieve the information about the constructor by using the getConstructors() method. Here is an example that provides the usage of the getConstructors() method.

Declare a class "Fconstructor" and then create an object of this class and take the reference of the class java.util.Integer.class into it. Make a Constructor named constructor. Now retrieve the name of the constructor by using the getConstructors() method.

Here is the code of the Example :

 

 

 

Fconstructor.java

import java.lang.reflect.*;

public class Fconstructor{
  public static void main(String[] args){
  Class cls = java.lang.String.class;
  Constructor constructor = cls.getConstructors()[0];
  String name;
  name = constructor.getName();  //It'll show java.lang.String
  System.out.println(name);
  }
}

Here is the output of the Example :

C:\roseindia>javac Fconstructor.java

C:\roseindia>java Fconstructor
java.lang.String

Download this Example:

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 28, 2008

Related Tutorials

Ask Questions?    Discuss: Getting information about Constructor  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com