remove Final Modifier - Java Reflection

Java examples for Reflection:Modifier

Description

remove Final Modifier

Demo Code


//package com.java2s;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class Main {
    public static void removeFinalModifier(final Field field)
            throws Exception {
        field.setAccessible(true);//from  w w w .  j  ava 2  s .  c  om
        final Field modifiersField = Field.class
                .getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField
                .setInt(field, field.getModifiers() & ~Modifier.FINAL);
    }
}

Related Tutorials