Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used boxed type when converting Variant to return type #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions runtime/src/main/java/com4j/DispatchComMethod.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com4j;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
* {@link ComMethod} that invokes through {@code IDispatch.Invoke}.
Expand All @@ -13,7 +15,6 @@ final class DispatchComMethod extends ComMethod {
final int flag;
final Class<?> retType;


DispatchComMethod( Method m ) {
super(m);

Expand All @@ -24,7 +25,10 @@ final class DispatchComMethod extends ComMethod {

flag = getFlag();

retType = m.getReturnType();
Class retType = m.getReturnType();
if (retType.isPrimitive() && boxTypeMap.containsKey(retType))
retType = boxTypeMap.get(retType);
this.retType = retType;
}

private int getFlag() {
Expand Down Expand Up @@ -58,4 +62,17 @@ Object invoke(long ptr, Object[] args) {
private static final int DISPATCH_PROPERTYPUT = 0x4;
@SuppressWarnings("unused")
private static final int DISPATCH_PROPERTYPUTREF = 0x8;

private static final Map<Class,Class> boxTypeMap = new HashMap<Class,Class>();

static {
boxTypeMap.put(byte.class,Byte.class);
boxTypeMap.put(short.class,Short.class);
boxTypeMap.put(int.class,Integer.class);
boxTypeMap.put(long.class,Long.class);
boxTypeMap.put(float.class,Float.class);
boxTypeMap.put(double.class,Double.class);
boxTypeMap.put(boolean.class,Boolean.class);
boxTypeMap.put(char.class,Character.class);
}
}