回答編集履歴

2

追記

2016/02/23 03:28

投稿

root_jp
root_jp

スコア4666

test CHANGED
@@ -69,3 +69,95 @@
69
69
  フレームワークを作る際には、リフレクションは必須ですが、
70
70
 
71
71
  その場合、フレームワークの使用者からはカプセル化されてて意識することもないですからね。
72
+
73
+
74
+
75
+ ###追記
76
+
77
+
78
+
79
+ ```Java
80
+
81
+ public class Main {
82
+
83
+ public static void main(String[] args) throws Exception {
84
+
85
+ Test test = new Test();
86
+
87
+ SetFunc(test, new Double(123.45));
88
+
89
+ SetFunc(test, new Integer(123));
90
+
91
+ SetFunc(test, new String("ABC"));
92
+
93
+
94
+
95
+ System.out.println(test);
96
+
97
+ }
98
+
99
+
100
+
101
+ public static void SetFunc(Test cls, Object value) throws Exception {
102
+
103
+ Method method = cls.getClass().getMethod("setTest", value.getClass());
104
+
105
+ method.invoke(cls, value);
106
+
107
+ }
108
+
109
+ }
110
+
111
+
112
+
113
+ class Test {
114
+
115
+ private Double A;
116
+
117
+ private Integer B;
118
+
119
+ private String C;
120
+
121
+
122
+
123
+ public void setTest(Double arg) {
124
+
125
+ A = arg;
126
+
127
+ }
128
+
129
+
130
+
131
+ public void setTest(Integer arg) {
132
+
133
+ B = arg;
134
+
135
+ }
136
+
137
+
138
+
139
+ public void setTest(String arg) {
140
+
141
+ C = arg;
142
+
143
+ }
144
+
145
+
146
+
147
+ @Override
148
+
149
+ public String toString() {
150
+
151
+ return new StringBuilder("A = ").append(A).append(System.lineSeparator())
152
+
153
+ .append("B = ").append(B).append(System.lineSeparator())
154
+
155
+ .append("C = ").append(C).append(System.lineSeparator())
156
+
157
+ .toString();
158
+
159
+ }
160
+
161
+ }
162
+
163
+ ```

1

追記

2016/02/23 03:28

投稿

root_jp
root_jp

スコア4666

test CHANGED
@@ -62,6 +62,8 @@
62
62
 
63
63
  ・デバッグがしづらく、バグの調査に苦労する
64
64
 
65
+ ・多用しなければ問題ないレベルだが、通常のコードよりは数倍遅い
66
+
65
67
 
66
68
 
67
69
  フレームワークを作る際には、リフレクションは必須ですが、