setLong() method of java.lang.reflect.Field used to set the value of a field as a long on the specified object. When you need to set the value of a field of an object as long then you can use this method to set value over an Object.
public void setLong(Object obj, long l) throws IllegalArgumentException, IllegalAccessException
Parameters: This method accepts accepts two parameters:
- obj: which is the object whose field should be modified and
- l: which is the new value for the field of obj being modified.
Return: This method returns nothing.
Exception: This method throws the following Exception:
- IllegalAccessException: if this Field object is enforcing Java language access control and the underlying field is either inaccessible or final.
- IllegalArgumentException: if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof), or if an unwrapping conversion fails.
- NullPolongerException: 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 setLong() method:
Value of salary before applying setLong is 1234567 Value of salary after applying setLong is 10000000 Value of uniqueNo before applying setLong is 234289 Value of uniqueNo after applying setLong is 2000000
Value after applying setLong is 36283435
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.