Skip to content

Commit 25d12df

Browse files
hansonrhansonr
authored andcommitted
fixes Method.invoke for primitives
1 parent aedb793 commit 25d12df

File tree

1 file changed

+20
-5
lines changed
  • sources/net.sf.j2s.java.core/src/java/lang/reflect

1 file changed

+20
-5
lines changed

sources/net.sf.j2s.java.core/src/java/lang/reflect/Method.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,33 @@ public Object invoke(Object receiver, Object... args)
109109
// proxy does
110110
Object[] a = Class.getArgumentArray(parameterTypes, args, isProxy);
111111
Object c = (isProxy ? receiver : this.Class_);
112+
Object m = null;
112113
/**
113114
* @j2sNative
114115
*
115116
* if (!this.isProxy) c = c.$clazz$;
116-
* var m= c[this.signature] || c.prototype && c.prototype[this.signature];
117-
* if (m != null)
118-
* return m.apply(receiver,a);
117+
* m= c[this.signature] || c.prototype && c.prototype[this.signature];
118+
* if (m != null) {
119+
* m = this.wrap(m.apply(receiver,a));
120+
* }
119121
*/
120-
122+
if (m == null) {
121123
String message = "Method " + getDeclaringClass().getName()
122124
+ "." + signature + " was not found";
123-
throw new IllegalArgumentException(message);
125+
throw new IllegalArgumentException(message);
126+
}
127+
return m;
128+
}
129+
130+
private Object wrap(Object o) {
131+
switch (/** @j2sNative typeof o || */"") {
132+
case "number":
133+
double d = (/** @j2sNative 1 ? o : */0);
134+
return (d == (int) d ? Integer.valueOf((int) d) : Double.valueOf(d));
135+
case "boolean":
136+
return Boolean.valueOf(/** @j2sNative o || */false);
137+
}
138+
return o;
124139
}
125140

126141
public TypeVariable<Method>[] getTypeParameters() {

0 commit comments

Comments
 (0)