- public class Triangle {
- // 定义三角形的三边
- protected long lborderA = 0;
- protected long lborderB = 0;
- protected long lborderC = 0;
- }
获得 protected 三个变量 (private 也一样)
- Triangle triangle = new Triangle(2, 2, 3);
- ry {
- Field title1 = triangle.getClass().getDeclaredField("lborderA");
- title1.setAccessible(true);
- Field title2 = triangle.getClass().getDeclaredField("lborderB");
- title2.setAccessible(true);
- Field title3 = triangle.getClass().getDeclaredField("lborderC");
- title3.setAccessible(true);
- long lborderA = (Long) title1.get(triangle);
- long lborderB = (Long) title2.get(triangle);
- long lborderC = (Long) title3.get(triangle);