zoukankan      html  css  js  c++  java
  • 反射的更改 更改 static final 静态常量的值 。 这样就能动态的更改 决定spring 用那一套实现

    public class Bean {
     
        public static final String dbtype=new String();
     
    }
     
     
    public static  void changFinalProperty(Class clazz ,Object newvalue)
        {
             
            try {
                Object o = clazz.newInstance();
                Field  field = clazz.getDeclaredField("dbtype");
                field.setAccessible(true);
                Field modifiersField = Field.class.getDeclaredField("modifiers");
                modifiersField.setAccessible(true);
                modifiersField.set(field, field.getModifiers() & ~Modifier.FINAL);
                field.set(null, newvalue);
            } catch (NoSuchFieldException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InstantiationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             
            System.out.println(Bean.dbtype);
        }
        
  • 相关阅读:
    Spring-Task
    bootstrap table分页(前后端两种方式实现)
    jquery file upload示例
    ajax传递list集合
    cogs 2383. [Hnoi2014]世界树 WD
    cogs 36.求和问题
    bolg
    noip2016
    cogs 1619. [HEOI2012]采花 AC
    leetcode[109]Convert Sorted List to Binary Search Tree
  • 原文地址:https://www.cnblogs.com/happyxiaomo/p/4512106.html
Copyright © 2011-2022 走看看