java.lang.reflect.Field.getLong()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(200)

本文整理了Java中java.lang.reflect.Field.getLong()方法的一些代码示例,展示了Field.getLong()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Field.getLong()方法的具体详情如下:
包路径:java.lang.reflect.Field
类名称:Field
方法名:getLong

Field.getLong介绍

[英]Returns the value of the field in the specified object as a long. 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.
[中]

代码示例

代码示例来源:origin: android-hacker/VirtualXposed

public long get(Object object) {
  try {
    return this.field.getLong(object);
  } catch (Exception e) {
    return 0;
  }
}

代码示例来源:origin: btraceio/btrace

/**
 * Gets the value of a static <code>long</code> field.
 *
 * @param field Field object whose value is returned.
 * @return the value of the <code>long</code> field
 */
public static long getLong(Field field) {
  checkStatic(field);
  try {
    return field.getLong(null);
  } catch (Exception exp) {
    throw translate(exp);
  }
}

代码示例来源:origin: redisson/redisson

public final long getLongValue(Object obj) throws IllegalAccessException {
  if (!isAndroid && memOffset >= 0) {
    return FSTUtil.unFlaggedUnsafe.getLong(obj, memOffset);
  }
  return field.getLong(obj);
}

代码示例来源:origin: spring-projects/spring-loaded

public long getReflectJ() throws Exception {
  return f_j.getLong(t);
}

代码示例来源:origin: btraceio/btrace

/**
 * Gets the value of an instance <code>long</code> field.
 *
 * @param field Field object whose value is returned.
 * @param obj the object to extract the <code>long</code> value
 * from
 * @return the value of the <code>long</code> field
 */
public static long getLong(Field field, Object obj) {
  try {
    return field.getLong(obj);
  } catch (Exception exp) {
    throw translate(exp);
  }
}

代码示例来源:origin: libgdx/libgdx

public long getContactAddr(Contact contact) {
    try {
      Field addrField = contact.getClass().getDeclaredField("addr");
      addrField.setAccessible(true);
      return addrField.getLong(contact);
    } catch (Exception e) {
      e.printStackTrace();
      return 0;
    }
  }
}

代码示例来源:origin: apache/geode

public long getLong(Object o) throws IllegalArgumentException, IllegalAccessException {
 return this.field.getLong(o);
}

代码示例来源:origin: spring-projects/spring-loaded

public static long callSetAndGetLong(Field thiz, Object o) throws IllegalArgumentException, IllegalAccessException {
  thiz.setLong(o, thiz.getLong(o));
  return thiz.getLong(o);
}

代码示例来源:origin: apache/incubator-dubbo

@Override
  void serialize(AbstractHessianOutput out, Object obj, Field field)
      throws IOException {
    long value = 0;
    try {
      value = field.getLong(obj);
    } catch (IllegalAccessException e) {
      log.log(Level.FINE, e.toString(), e);
    }
    out.writeLong(value);
  }
}

代码示例来源:origin: spring-projects/spring-loaded

public Long gf() throws Exception {
    Field f = Thirteen.class.getField("foo");
    return f.getLong(this);
  }
}

代码示例来源:origin: spring-projects/spring-loaded

public static long callSetLong(Field thiz, Object o) throws IllegalArgumentException, IllegalAccessException {
  thiz.setLong(o, 12345);
  return thiz.getLong(o);
}

代码示例来源:origin: RuedigerMoeller/fast-serialization

public final long getLongValue(Object obj) throws IllegalAccessException {
  if (!isAndroid && memOffset >= 0) {
    return FSTUtil.unFlaggedUnsafe.getLong(obj, memOffset);
  }
  return field.getLong(obj);
}

代码示例来源:origin: apache/ignite

@Override public Field run() {
    try {
      Field addrFld = Buffer.class.getDeclaredField("address");
      addrFld.setAccessible(true);
      if (addrFld.getLong(maybeDirectBuf) == 0)
        throw new RuntimeException("java.nio.DirectByteBuffer.address field is unavailable.");
      return addrFld;
    }
    catch (Exception e) {
      throw new RuntimeException("java.nio.DirectByteBuffer.address field is unavailable.", e);
    }
  }
});

代码示例来源:origin: robovm/robovm

private float getFloat(Object object, Class<?> fieldType, Class<?> expectedType) {
  if (fieldType == Float.TYPE) {
    return getF(object, field);
  }
  return getLong(object, fieldType, expectedType); 
}

代码示例来源:origin: Qihoo360/XLearning

private static synchronized String getPidOfProcess(Process p) {
 long pid = -1;
 try {
  if (p.getClass().getName().equals("java.lang.UNIXProcess")) {
   Field f = p.getClass().getDeclaredField("pid");
   f.setAccessible(true);
   pid = f.getLong(p);
   f.setAccessible(false);
  }
 } catch (Exception e) {
  pid = -1;
 }
 return Long.toString(pid);
}

代码示例来源:origin: apache/geode

public ClassAndVariables(CompiledClass parsedClass) {
 this.dclass = parsedClass;
 String name = dclass.fullyQualifiedName().replace('/', '.');
 try {
  Class realClass = Class.forName(name);
  Field field = realClass.getDeclaredField("serialVersionUID");
  field.setAccessible(true);
  serialVersionUID = field.getLong(null);
  hasSerialVersionUID = true;
 } catch (NoSuchFieldException e) {
  // No serialVersionUID defined
 } catch (Throwable e) {
  System.out.println("Unable to load" + name + ":" + e);
 }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

private static long cpuSampling() throws NoSuchFieldException, IllegalAccessException {
  return profilingModes.getDeclaredField("CPU_SAMPLING").getLong(profilingModes);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

private static long snapshotWithoutHeap() throws NoSuchFieldException, IllegalAccessException {
  return profilingModes.getDeclaredField("SNAPSHOT_WITHOUT_HEAP").getLong(profilingModes);
}

代码示例来源:origin: org.easymock/easymock

private static Long getSerializableUID(Class<?> clazz) {
  try {
    Field f = clazz.getDeclaredField("serialVersionUID");
    int mask = Modifier.STATIC | Modifier.FINAL;
    if ((f.getModifiers() & mask) == mask) {
      f.setAccessible(true);
      return f.getLong(null);
    }
  } catch (NoSuchFieldException e) {
    // It's not there, compute it then
  } catch (IllegalAccessException e) {
    // ///CLOVER:OFF
    throw new RuntimeException("Should have been able to get serialVersionUID since it's there");
    // ///CLOVER:ON
  }
  // ///CLOVER:OFF
  return callLongMethod(clazz,
      ClassInstantiatorFactory.is1_3Specifications() ? "computeSerialVersionUID"
          : "computeDefaultSUID");
  // ///CLOVER:ON
}

代码示例来源:origin: apache/flink

@Test
  public void validateUid() {
    Field uidField;
    try {
      uidField = KafkaTopicPartition.class.getDeclaredField("serialVersionUID");
      uidField.setAccessible(true);
    }
    catch (NoSuchFieldException e) {
      fail("serialVersionUID is not defined");
      return;
    }

    assertTrue(Modifier.isStatic(uidField.getModifiers()));
    assertTrue(Modifier.isFinal(uidField.getModifiers()));
    assertTrue(Modifier.isPrivate(uidField.getModifiers()));

    assertEquals(long.class, uidField.getType());

    // the UID has to be constant to make sure old checkpoints/savepoints can be read
    try {
      assertEquals(722083576322742325L, uidField.getLong(null));
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
}

相关文章

微信公众号

最新文章

更多