zoukankan      html  css  js  c++  java
  • DirectFieldAccessor的使用场景(好多图)

    1、背景:

    在项目中遇到某实例中的某个属性被声明为private ,而且实体类中,不提供该属性的get方法,导致无法通过get获取该属性值。这个时候,我们可以利用DirectFieldAccessor这个类进行获取我们想要的属性值。

    2、作用

    它的功能是直接操作Bean的属性值,代替使用get/set方法去操作Bean。

    3、使用案例

    class User {
    
        private int id ;
    
        private Ving ving = new Ving();
    
        public User(int id) {
            this.id = id;
        }
    }
    
    class Ving{
        public int activeCount = 6;
    }
    
    public class TestDirectClass {
    
        @Test
        public void testDirectFieldAccessor() {
            User user = new User(111);
    
            DirectFieldAccessor accessor = new DirectFieldAccessor(user);
            TypeDescriptor id = accessor.getPropertyTypeDescriptor("id");
            System.out.println(id.getName());
            Object idValue = accessor.getPropertyValue("id");
            System.out.println("idValue:" +idValue);
    
            Ving ving = (Ving)accessor.getPropertyValue("ving");
            System.out.println(ving.activeCount);
    
        }
    
        @Test
        public void testPropertyAccessorFactory() {
            User user = new User(111);
    
            ConfigurablePropertyAccessor configurablePropertyAccessor = PropertyAccessorFactory.forDirectFieldAccess(user);
    
            TypeDescriptor id = configurablePropertyAccessor.getPropertyTypeDescriptor("id");
    
            System.out.println(id.getName());
    
            Object idValue = configurablePropertyAccessor.getPropertyValue("id");
            System.out.println("idValue:" +idValue);
    
            Ving ving = (Ving)configurablePropertyAccessor.getPropertyValue("ving");
            System.out.println(ving.activeCount);
    
    
        }
    }
  • 相关阅读:
    (六)定时测量
    (五)内核同步
    (四)中断和异常
    smba
    (四)支持 Nand Flash
    (三) 支持Nor Flash
    Convolutional Neural Networks(5):Pooling Layer
    Convolutional Neural Networks(4):Feature map size,Padding and Stride
    Convolutional Neural Networks(3):Convolution and Channels
    Convolutional Neural Networks(2):Sparse Interactions, Receptive Field and Parameter Sharing
  • 原文地址:https://www.cnblogs.com/vingLiu/p/12199860.html
Copyright © 2011-2022 走看看