質問編集履歴
4
追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -63,3 +63,79 @@
|
|
63
63
|
|
64
64
|
|
65
65
|
ご教示の程、よろしくお願い致します。
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
---
|
72
|
+
|
73
|
+
**追記**
|
74
|
+
|
75
|
+
```java
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
class Test {
|
80
|
+
|
81
|
+
private float D;
|
82
|
+
|
83
|
+
private Double A;
|
84
|
+
|
85
|
+
private Integer B;
|
86
|
+
|
87
|
+
private String C;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
public void setTest(float arg) { D=arg; } // float型が引数
|
92
|
+
|
93
|
+
public void setTest(Double arg) { A=arg; }
|
94
|
+
|
95
|
+
public void setTest(Integer arg) { B=arg; }
|
96
|
+
|
97
|
+
public void setTest(String arg) { C=arg; }
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
```
|
104
|
+
|
105
|
+
```java
|
106
|
+
|
107
|
+
public class JavaApp {
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
public static void main(String[] args) throws Exception {
|
112
|
+
|
113
|
+
Test test = new Test();
|
114
|
+
|
115
|
+
SetFunc(test, 123.4f);
|
116
|
+
|
117
|
+
SetFunc(test, new Double(123.45d));
|
118
|
+
|
119
|
+
SetFunc(test, new Integer(123));
|
120
|
+
|
121
|
+
SetFunc(test, new String("ABC"));
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
public static void SetFunc(Test cls, Object value) throws Exception {
|
128
|
+
|
129
|
+
Method method = cls.getClass().getMethod("setTest", value.getClass());
|
130
|
+
|
131
|
+
method.invoke(cls, value);
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
```
|
3
サンプルコード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,7 +48,7 @@
|
|
48
48
|
|
49
49
|
Method method = cls.getClass().getMethod("setTest", <<1>>);
|
50
50
|
|
51
|
-
method.invoke(
|
51
|
+
method.invoke(cls, <<2>>);
|
52
52
|
|
53
53
|
}
|
54
54
|
|
2
サンプルコード間違い修正
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
タイトルの変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
getMethodの引数について
|
1
|
+
getMethod、invokeの第2引数について
|
test
CHANGED
File without changes
|