Issue
I'm wondering How can I pass field name of a class as parameter to include it in a String?
For example, let's say I have a class A with this members :
public class A {
String name;
String reference;
....
}
What I want, is to be able to initialize a string having as parameters one of the two classe field name to display it dynamically. So for instance, I want to do this :
System.out.println("the field {nameField} belong to class A.");
And in output I would have this :
output : the field name belong to class A.
Is that possible in Java ?
Any help would be much appreciated ?
Regards
YT
Solution
This can be done by use of reflection in Java. https://www.oracle.com/technical-resources/articles/java/javareflection.html#:~:text=Reflection%20is%20a%20feature%20in,its%20members%20and%20display%20them.
Answered By - Harshita Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.