mercredi 19 juillet 2017

is there any way to write functions or methods body dynamically in scala or java

I wanted to know is there any way to write method's body dynamically. i.e. Reading conditions from XML or JSON and depending on these conditions defining method's body.

If I have not expressed the example in right way please forgive me.

Ex:

def read(conds: Array[String])={
    var str = ""
    for(i <- 0 to conds.length - 1){
      if(conds(i) == "1"){
        //add if code to str
        //if(){
          //if cond code here
        //}
      }else if(conds(i) == "2"){
        //add else if code to str
        //else if(){
          //else if cond code here
        //}
      }else if(conds(i) == "3"){
        //add else code to str
        //else{
          //else code here
        //}
      }
    }

    //at the end str has multiple conditions
    //Ex:
    //str = "if(){....}"+
    //"esle if(){....}"+
    //"esle if(){....}"+
    //"esle if(){....}"+
    //"esle{....}"
    //so all the code present in string should be body of method
  }





Aucun commentaire:

Enregistrer un commentaire