Java Field.getShort(Object obj)

Syntax

Field.getShort(Object obj) has the following syntax.

public short getShort(Object obj)  throws IllegalArgumentException ,   IllegalAccessException

Example

In the following code shows how to use Field.getShort(Object obj) method.


//  w w w.ja v  a  2 s  . c om
import java.lang.reflect.Field;

class MyClass {
  public short i = 9;
}

public class Main {
  public static void main(String[] args) throws Exception {
    Class<?> clazz = Class.forName("MyClass");
    MyClass x = (MyClass) clazz.newInstance();

    Field f = clazz.getField("i");
    System.out.println(f.getShort(x));
    
    f.setShort(x, (short)9);
    System.out.println(f.getShort(x)); 

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable