Skip to content

Commit

Permalink
update MethodInvoker
Browse files Browse the repository at this point in the history
  • Loading branch information
tvd12 committed Aug 26, 2021
1 parent ecb5e16 commit 6d9d265
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/tvd12/test/reflect/MethodInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ public MethodInvoker object(Object object) {
return this;
}

/**
* invoke method and cast returned result with type
*
* @param <T> the output type
* @return the value returned by the invoked method
*/
@SuppressWarnings("unchecked")
public <T> T call() {
return (T)invoke();
}

/**
* invoke method
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public void test() {
.object(new B())
.invoke(String.class);
assert get.equals("private method: 1-a");

String call = MethodInvoker.create()
.method("get")
.param(int.class, 1)
.params("a")
.object(new B())
.call();
assert call.equals("private method: 1-a");
}

public static class ClassA {
Expand Down

0 comments on commit 6d9d265

Please sign in to comment.