java.lang.reflect.Constructor.isVarArgs() Method Example


Advertisements


Description

The java.lang.reflect.Constructor.isVarArgs() method returns true if this constructor was declared to take a variable number of arguments; returns false otherwise.

Declaration

Following is the declaration for java.lang.reflect.Constructor.isVarArgs() method.

public boolean isVarArgs()

Returns

true if an only if this constructor was declared to take a variable number of arguments.

Example

The following example shows the usage of java.lang.reflect.Constructor.isVarArgs() method.

Live Demo
package com.tutorialspoint;

import java.lang.reflect.Constructor;

public class ConstructorDemo {
   public static void main(String[] args) {

      Constructor[] constructors = SampleClass.class.getConstructors();
      System.out.println(constructors[1].isVarArgs());
   }
}

class SampleClass {
   private String sampleField;
   
   public SampleClass(){
   }

   public SampleClass(String sampleField){
      this.sampleField = sampleField;
   }

   public String getSampleField() {
      return sampleField;
   }

   public void setSampleField(String sampleField) {
      this.sampleField = sampleField;
   } 
}

Let us compile and run the above program, this will produce the following result −

false

java_reflect_constructor.htm


Advertisements
E-Books Store