Field getLong() method in Java with Examples
The getLong() method of java.lang.reflect.Field used to get the value of long which has to be static or instance field type. This method also used to get the value of another primitive type convertible to type long via a widening conversion. When a class contains a static or instance long field and we want to get the value of that field then we can use this method to return the value of Field.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public long getLong(Object obj) throws IllegalArgumentException, IllegalAccessException
Parameters: This method accepts a single parameter obj which is the object to extract the long value from.
Return value: This method returns the value of field converted to type long.
Exception: This method throws following Exception:
- IllegalAccessException: if Field object is enforcing Java language access control and the underlying field is inaccessible.
- IllegalArgumentException: if the specified object is not an instance of the class or interface declaring the underlying field or if the field value cannot be converted to the type long by a widening conversion.
- NullPointerException: if the specified object is null and the field is an instance field.
- ExceptionInInitializerError: if the initialization provoked by this method fails.
Below programs illustrate getLong() method:
Value of long Field HighScore is 341313432299133