java.lang.reflect.Modifier的isPrivate(mod)方法用于检查integer参数是否包含private修饰符。如果此整数参数表示私有类型Modifier,则方法返回true,否则返回false。
用法:
public static boolean isPrivate(int mod)
参数:此方法接受整数名称,因为mod代表一组修饰符。
返回:如果mod包含private修饰符,则此方法返回true;否则,返回false。否则为假。
以下示例程序旨在说明isPrivate()方法:
示例1:
// Java program to illustrate isPrivate() method
import java.lang.reflect.*;
public class GFG {
// create a String Field
private String string;
public static void main(String[] args)
throws NoSuchFieldException,
SecurityException
{
// get Field class object
Field field
= GFG.class
.getDeclaredField("string");
// get Modifier Integer value
int mod = field.getModifiers();
// check Modifier is private or not
boolean result = Modifier.isPrivate(mod);
System.out.println("Mod integer value "
+ mod + " is private : "
+ result);
}
}
输出:
Mod integer value 2 is private : true
示例2:
// Java program to illustrate isPrivate()
import java.lang.reflect.*;
public class GFG {
// create an int Field
public int numbers;
public static void main(String[] args)
throws NoSuchFieldException,
SecurityException
{
// get Field class object
Field field
= GFG.class
.getDeclaredField("numbers");
// get Modifier Integer value
int mod = field.getModifiers();
// check Modifier is private or not
boolean result
= Modifier.isPrivate(mod);
System.out.println("Mod integer value "
+ mod + " is private : "
+ result);
}
}
输出:
Mod integer value 1 is private : false