Java reflection invoke method with parameters|Java reflection invoke methods |  java reflection api

Java reflection invoke method with parameters|Java reflection invoke methods | java reflection api

Bytecode Velocity

3 года назад

4,196 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@segujjajoseph9183
@segujjajoseph9183 - 05.01.2023 11:07

How deal with a method with empty parameters

Ответить
@MrDeepakLalchandani
@MrDeepakLalchandani - 31.05.2022 16:13

import java.util.*;
import java.lang.reflect;

class invokeOperation{
public static void main(String args[]){
invokeOperation io = new invokeOperation();

final String[] OPERATION_LIST = {"add","sub","div","cos" };

String condition = getCondition();

for (String op : OPERATION_LIST) {
if (condition.equals(op)){
io.getClass().getMethod(op).invoke(this);
}else{
break;
}
}

public String getCondition(){
return "add";
}
}
}

Ответить
@anshumandash6053
@anshumandash6053 - 14.02.2022 22:02

Thank you so much! I was struggling for so long trying to do this, and you explained it beautifully in just 5 min

Ответить
@shahidanwar6254
@shahidanwar6254 - 21.12.2021 12:06

how to pass multiple parameters for the method here?

Ответить