java.lang.reflect.Modifier的isTransient(mod)方法用於檢查整數參數是否包含瞬態修飾符。如果此整數參數表示瞬時類型Modifier,則方法返回true,否則返回false。
用法:
public static boolean isTransient(int mod)
參數:此方法接受整數名稱,因為mod代表一組修飾符。
返回:如果mod包含瞬時修飾符,則此方法返回true;否則為假。
以下示例程序旨在說明isTransient()方法:
示例1:
// Java program to illustrate isTransient() method
import java.lang.reflect.*;
public class GFG {
public static transient int number = 1000;
public static void main(String[] args)
throws NoSuchFieldException,
SecurityException
{
// get Field class object
Field field
= GFG
.class
.getDeclaredField("number");
// get Modifier Integer value
int mod = field.getModifiers();
// check Modifier is transient or not
boolean result
= Modifier.isTransient(mod);
System.out.println("Mod integer value "
+ mod + " is transient : "
+ result);
}
}
輸出:
Mod integer value 137 is transient : true
示例2:
// Java program to illustrate isTransient()
import java.io.Serializable;
import java.lang.reflect.*;
public class GFG {
public static void main(String[] args)
throws NoSuchFieldException,
SecurityException
{
// get Field class object
Field field
= GFGTest
.class
.getDeclaredField("password");
// get Modifier Integer value
int mod = field.getModifiers();
// check Modifier is transient or not
boolean result = Modifier.isTransient(mod);
System.out.println("Mod integer value "
+ mod
+ " is transient : "
+ result);
}
// A sample class that uses a transient keyword to
// skip their serialization.
class GFGTest implements Serializable {
// Making password transient for security
private transient String password;
// other code
}
}
輸出:
Mod integer value 130 is transient : true
參考文獻: https://docs.oracle.com/javase/10/docs/api/java/lang/reflect/Modifier.html#isTransient(int)
相關用法
- Java Modifier isNative(mod)用法及代碼示例
- Java Modifier isAbstract(mod)用法及代碼示例
- Java Modifier isPublic(mod)用法及代碼示例
- Java Modifier isPrivate(mod)用法及代碼示例
- Java Modifier isStrict(mod)用法及代碼示例
- Java Modifier isSynchronized(mod)用法及代碼示例
- Java Modifier isVolatile(mod)用法及代碼示例
- Java Modifier isProtected(mod)用法及代碼示例
- Java Modifier isStatic(mod)用法及代碼示例
- Java Modifier isFinal(mod)用法及代碼示例
- Java Modifier isInterface(mod)用法及代碼示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 Modifier isTransient(mod) method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。