本文整理了Java中java.lang.reflect.Field.setBoolean()
方法的一些代码示例,展示了Field.setBoolean()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Field.setBoolean()
方法的具体详情如下:
包路径:java.lang.reflect.Field
类名称:Field
方法名:setBoolean
[英]Sets the value of the field in the specified object to the boolean value. This reproduces the effect of object.fieldName =
If this field is static, the object argument is ignored. Otherwise, if the object is null, a NullPointerException is thrown. If the object is not an instance of the declaring class of the method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
If the value cannot be converted to the field type via a widening conversion, an IllegalArgumentException is thrown.
[中]将指定对象中字段的值设置为布尔值。这再现了对象的效果。字段名=
如果此字段是静态的,则忽略对象参数。否则,如果对象为null,则抛出NullPointerException。如果该对象不是该方法声明类的实例,则会引发IllegalArgumentException。
如果此字段对象正在强制访问控制(请参见AccessibleObject),并且无法从当前上下文访问此字段,则会引发IllegaAccessException。
如果无法通过加宽转换将值转换为字段类型,则会引发IllegalArgumentException。
代码示例来源:origin: android-hacker/VirtualXposed
public void set(Object obj, boolean value) {
try {
this.field.setBoolean(obj, value);
} catch (Exception e) {
//Ignore
}
}
}
代码示例来源:origin: stackoverflow.com
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception ignored) {
}
代码示例来源:origin: stackoverflow.com
private void makeActionOverflowMenuShown() {
//devices with hardware menu button (e.g. Samsung Note) don't show action overflow menu
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
Log.d(TAG, e.getLocalizedMessage());
}
}
代码示例来源:origin: spring-projects/spring-loaded
public static boolean callSetBoolean(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setBoolean(obj, true);
return thiz.getBoolean(obj);
}
代码示例来源:origin: spring-projects/spring-loaded
public void setIntZ() throws Exception {
f_z.setAccessible(true);
f_z.setBoolean(t, false);
}
代码示例来源:origin: stackoverflow.com
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
}
catch (Exception e) {
// presumably, not relevant
}
代码示例来源:origin: spring-projects/spring-loaded
public static boolean callSetAndGetBoolean(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setBoolean(obj, !thiz.getBoolean(obj));
return thiz.getBoolean(obj);
}
代码示例来源:origin: redisson/redisson
public final void setBooleanValue(Object newObj, boolean i1) throws IllegalAccessException {
if (!isAndroid && memOffset >= 0) {
FSTUtil.unFlaggedUnsafe.putBoolean(newObj, memOffset, i1);
return;
}
field.setBoolean(newObj, i1);
}
代码示例来源:origin: stackoverflow.com
private void getOverflowMenu() {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: spotbugs/spotbugs
private void setField(String fieldName, boolean value) {
try {
Field f = FilterCommandLine.class.getField(fieldName);
f.setBoolean(this, value);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static void disablePrimitiveOptimization(Object self) {
Field sdyn;
Class c = self.getClass();
try {
sdyn = c.getDeclaredField(Verifier.STATIC_METACLASS_BOOL);
sdyn.setBoolean(null, true);
} catch (Throwable e) {
//DO NOTHING
}
}
代码示例来源:origin: apache/flink
@VisibleForTesting
static void resetRocksDBLoadedFlag() throws Exception {
final Field initField = org.rocksdb.NativeLibraryLoader.class.getDeclaredField("initialized");
initField.setAccessible(true);
initField.setBoolean(null, false);
}
}
代码示例来源:origin: yhaolpz/FloatWindow
private static void setMiUI_International(boolean flag) {
try {
Class BuildForMi = Class.forName("miui.os.Build");
Field isInternational = BuildForMi.getDeclaredField("IS_INTERNATIONAL_BUILD");
isInternational.setAccessible(true);
isInternational.setBoolean(null, flag);
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: Meituan-Dianping/Robust
public static void setFieldValue(String name, Object instance, boolean value, Class cl) {
try {
getReflectField(name, instance, cl).setBoolean(instance, value);
} catch (Exception e) {
e.printStackTrace();
if (isThrowable) {
throw new RuntimeException("setFieldValue boolean error " + name + " target " + instance + " value " + value);
}
}
}
代码示例来源:origin: Meituan-Dianping/Robust
public static void setStaticFieldValue(String name, Class clazz, boolean value) {
try {
getReflectStaticField(name, clazz).setBoolean(null, value);
} catch (Exception e) {
e.printStackTrace();
if (isThrowable) {
throw new RuntimeException("setStaticFieldValue boolean error " + name + " Class " + clazz + " value " + value);
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
void deserialize(AbstractHessianInput in, Object obj)
throws IOException {
boolean value = false;
try {
value = in.readBoolean();
_field.setBoolean(obj, value);
} catch (Exception e) {
logDeserializeError(_field, obj, value, e);
}
}
}
代码示例来源:origin: apache/zookeeper
/**
* Prevent the client from automatically reconnecting if the connection to the
* server is lost
*/
public void dontReconnect() throws Exception {
java.lang.reflect.Field f = cnxn.getClass().getDeclaredField("closing");
f.setAccessible(true);
f.setBoolean(cnxn, true);
}
}
代码示例来源:origin: apache/zookeeper
private void setSaslFailureFlag(ZooKeeper zk) throws Exception {
Field cnxnField = zk.getClass().getDeclaredField("cnxn");
cnxnField.setAccessible(true);
ClientCnxn clientCnxn = (ClientCnxn) cnxnField.get(zk);
Field sendThreadField = clientCnxn.getClass().getDeclaredField("sendThread");
sendThreadField.setAccessible(true);
SendThread sendThread = (SendThread) sendThreadField.get(clientCnxn);
Field saslLoginFailedField = sendThread.getClass().getDeclaredField("saslLoginFailed");
saslLoginFailedField.setAccessible(true);
saslLoginFailedField.setBoolean(sendThread, true);
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
public DatePatternConverterTest(final Boolean threadLocalEnabled) throws Exception {
// Setting the system property does not work: the Constant field has already been initialized...
//System.setProperty("log4j2.enable.threadlocals", threadLocalEnabled.toString());
final Field field = Constants.class.getDeclaredField("ENABLE_THREADLOCALS");
field.setAccessible(true); // make non-private
final Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); // make non-final
field.setBoolean(null, threadLocalEnabled.booleanValue());
}
代码示例来源:origin: btraceio/btrace
@BeforeClass
public static void classSetup() throws Exception {
try {
Field f = RandomIntProvider.class.getDeclaredField("useBtraceEnter");
f.setAccessible(true);
f.setBoolean(null, false);
} catch (Exception e) {
e.printStackTrace();
}
}
内容来源于网络,如有侵权,请联系作者删除!