java.lang.reflect.Modifier.isStatic() Method Example



Description

The java.lang.reflect.Modifier.isStatic(int mod) method return true if the integer argument includes the static modifier, false otherwise.

Declaration

Following is the declaration for java.lang.reflect.Modifier.isStatic(int mod) method.

public static boolean isStatic(int mod)

Parameters

mod − a set of modifiers.

Returns

true if mod includes the static modifier; false otherwise.

Example

The following example shows the usage of java.lang.reflect.Modifier.isStatic(int mod) method.

package com.tutorialspoint;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class ModifierDemo {
   public static void main(String[] args) throws NoSuchFieldException, SecurityException {
      Field field = SampleClass.class.getDeclaredField("sampleField");
      System.out.println(Modifier.isStatic(field.getModifiers()));
   }
}

class SampleClass {
   public static String sampleField;
   
   public final 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 −

true
java_reflect_modifier.htm
Advertisements