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

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

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

Field.getDouble介绍

[英]Returns the value of the field in the specified object as a double. 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.
[中]以双精度形式返回指定对象中字段的值。这再现了对象的效果。字段名
如果此字段是静态的,则忽略对象参数。否则,如果对象为null,则抛出NullPointerException。如果该对象不是该方法声明类的实例,则会引发IllegalArgumentException。
如果此字段对象正在强制访问控制(请参见AccessibleObject),并且无法从当前上下文访问此字段,则会引发IllegaAccessException。

代码示例

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

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

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

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

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

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

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

public double getReflectD() throws Exception {
  return f_d.getDouble(t);
}

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

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

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

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

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

public static double callSetAndGetDouble(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
  thiz.setDouble(obj, thiz.getDouble(obj) + 1.5);
  return thiz.getDouble(obj);
}

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

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

代码示例来源:origin: stackoverflow.com

Field f = R.class.getField("_1st");
Class<?> t = f.getType();
if(t == int.class){
  System.out.println(f.getInt(null));
}else if(t == double.class){
  System.out.println(f.getDouble(null));
}...

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

/** Returns the pair of metric name and metric value. */
  public Map<String, Double> toMap() {
    Map<String, Double> metricValues = new HashMap<>();
    for (Field field : getClass().getDeclaredFields())
      try {
        metricValues.put(field.getName(), field.getDouble(this));
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      }
    return metricValues;
  }
}

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

public static double callSetDouble(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
  thiz.setDouble(obj, 1.234);
  return thiz.getDouble(obj);
}

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

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

代码示例来源:origin: h2oai/h2o-2

@Override public String toString() {
  Field[] fields = getFields(this);
  String r="";
  for( Field field : fields ){
   String name = field.getName();
   Class cl = field.getType();
   try{
    if( cl.isPrimitive() ){
     if( cl == Boolean.TYPE ){
      boolean curval = field.getBoolean(this);
      if( curval ) r += " -"+name;
     }
     else if( cl == Integer.TYPE ) r+=" -"+name+"="+field.getInt(this);
     else if( cl == Float.TYPE )  r+=" -"+name+"="+field.getFloat(this);
     else if( cl == Double.TYPE )  r+=" -"+name+"="+field.getDouble(this);
     else if( cl == Long.TYPE )  r+=" -"+name+"="+field.getLong(this);
     else continue;
    } else if( cl == String.class )
     if (field.get(this)!=null) r+=" -"+name+"="+field.get(this);
   } catch( Exception e ) { Log.err("Argument failed with ",e); }
  }
  return r;
 }
}

代码示例来源:origin: stanfordnlp/CoreNLP

rep.append(joiner).append(name).append('=').append(val);
} else if (type.equals(double.class)) {
 double val = ff.getDouble(this);
 rep.append(joiner).append(name).append('=').append(val);
} else if (type.equals(Integer.class)) {

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

/**
 * Returns the value of the field in the specified object as a {@code
 * double}. This reproduces the effect of {@code object.fieldName}
 * <p>
 * If this field is static, the object argument is ignored.
 * Otherwise, if the object is {@code null}, a NullPointerException is
 * thrown. If the object is not an instance of the declaring class of the
 * method, an IllegalArgumentException is thrown.
 * <p>
 * If this Field object is enforcing access control (see AccessibleObject)
 * and this field is not accessible from the current context, an
 * IllegalAccessException is thrown.
 *
 * @param object
 *            the object to access
 * @return the field value
 * @throws NullPointerException
 *             if the object is {@code null} and the field is non-static
 * @throws IllegalArgumentException
 *             if the object is not compatible with the declaring class
 * @throws IllegalAccessException
 *             if this field is not accessible
 */
public double getDouble(Object object)
    throws IllegalAccessException, IllegalArgumentException {
      
  checkAccess(object, false);
  checkReceiver(object);
  return getDouble(object, getType(), Double.TYPE);
}

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

output.writeChar(field.getChar(obj));
} else if (type == double.class) {
  output.writeDouble(field.getDouble(obj));
} else if (type == float.class) {
  output.writeFloat(field.getFloat(obj));

代码示例来源:origin: webx/citrus

void serialize(AbstractHessianOutput out, Object obj, Field field)
      throws IOException {
    double value = 0;
    try {
      value = field.getDouble(obj);
    } catch (IllegalAccessException e) {
      log.log(Level.FINE, e.toString(), e);
    }
    out.writeDouble(value);
  }
}

代码示例来源:origin: webx/citrus

void serialize(AbstractHessianOutput out, Object obj, Field field)
      throws IOException {
    double value = 0;
    try {
      value = field.getDouble(obj);
    } catch (IllegalAccessException e) {
      log.log(Level.FINE, e.toString(), e);
    }
    out.writeDouble(value);
  }
}

代码示例来源:origin: com.esotericsoftware/kryo

public void write (Output output, Object object) {
  try {
    output.writeDouble(field.getDouble(object));
  } catch (Exception e) {
    KryoException ex = new KryoException(e);
    ex.addTrace(this + " (" + type.getName() + ")");
    throw ex;
  }
}

代码示例来源:origin: com.esotericsoftware/kryo

public void copy (Object original, Object copy) {
    try {
      field.setDouble(copy, field.getDouble(original));
    } catch (Exception e) {
      KryoException ex = new KryoException(e);
      ex.addTrace(this + " (" + type.getName() + ")");
      throw ex;
    }
  }
}

相关文章

微信公众号

最新文章

更多