vendredi 3 mai 2019

Get all the local variables in a method java [duplicate]

This question already has an answer here:

How to get all the fields declared inside the method of a class. Something similar to class.getDeclaredFields() ?

public static void main(String[] args) {

        Class<String> clazz = String.class;

        Stream.of(clazz.getDeclaredFields()).forEach(field ->{
            System.out.println(field.getName()+" -> "+field.getType());
        });

}

The Above code returns all the fields declared in the class, can we do it at methods level to return all the local variables in the method.





Aucun commentaire:

Enregistrer un commentaire